How to Install Composer PHP Dependency Manager on Debian 8 and Ubuntu 14.04

Composer is a dependency manager for PHP. It helps you declare, manage and install dependencies of PHP projects. Starting with Debian 9 Stretch and Ubuntu 16.04 Xenial, Composer is available from Debian and Ubuntu repository. So Debian 9 and Ubuntu 16.04, 16.10 users can quickly install it using the following command:

sudo apt install composer

But Debian 8 and Ubuntu 14.04 users need to follow the composer install command below.

Composer Install Command on Debian 8 and Ubuntu 14.04

Make sure PHP command line interface is installed:

sudo apt install php-cli

Then use the below command to download the Composer installer to the current directory. It will be saved as composer-setup.php.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

Next, run the below command to verify the installer SHA-384 so it can be trusted.

php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

If the verification is successful, you will see the following message.

Installer Verified

Now run the installer. This tutorial installs composer to the system-wide /usr/local/bin directory and specify composer as the filename. Since /usr/local/bin/ is in the user’s PATH, it allows the user to use composer command globally.

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

The installer will check php.ini file for incorrect settings, and then download the latest composer.phar to the /usr/local/bin and rename the filename to composer. Here’s a sample output:

install composer on debina 8 jessie and ubuntu 14.04 trusty
To remove the Composer installer from the current dirctory, run:

php -r "unlink('composer-setup.php');"

You can see a list of option and available command of Composer by executing composer command.

composer

composer php dependency manager

I hope this tutorial helped you to install Composer PHP dependency manager on Debian 8 and Ubuntu 14.04. As always, if you found this post useful, subscribe to our free newsletter or follow us on Google+Twitter or like our Facebook page.

Rate this tutorial
[Total: 1 Average: 5]