How Do You Install Composer on Debian/Ubuntu Linux?

Problem scenario
You want to install Composer (a dependency manager for PHP) on your Debian/Ubuntu Linux server. What do you do?

Solution

  1. Run these commands:

sudo apt -y update
sudo apt -y install php-cli unzip
cd ~
sudo curl -sS https://getcomposer.org/installer -o composer-setup.php
HASH=curl -sS https://composer.github.io/installer.sig
echo $HASH
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

  1. The last command above should have printed out "Installer verified". Now run these two commands:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer

  1. You are done. The above directions were adapted from this external page.
  2. The above directions were tested to work on Debian 10.

Leave a comment

Your email address will not be published. Required fields are marked *