How to Install PHP Composer On Debian Linux


Install the Composer PHP package manager on Debian.


This guide focuses on Debian, but may work with Ubuntu as well.


A working Debian install with root privileges.




  • # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ – requires given linux commands to be executed as a regular non-privileged user


Composer is a PHP package manager that assists in the installation and management of PHP packages. It also helps handle project dependencies. As a result, many modern PHP projects rely on Composer.

Though Composer is in the Debian repositories, the version there is terribly out-of-date. Installing it directly from the development team is easy regardless.

Install The Dependencies

There are only a couple of things that you’ll need in order to get Composer running. Go ahead and install them with Apt.

$ sudo apt install php-cli git

Grab The Installer

cd into your /tmp directory. It’s just easier to clean up after the installation that way.

Once there, use PHP to grab the installer.

$ php -r "copy('', 'composer-setup.php');"

Check The Integrity

It won’t take long to download the installer. It’s best to verify the integrity of the installer after you have it. Go to the Composer website’s signature page, and copy the signature at the top of the page. Then, plug it in to the following linux command.

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

Replace “SIGNATURE” with the one you copied from the site. If the command returns “Installer verified,” you’re good to keep going.

Install Composer

You have the option of where you want to install Composer. You can either install it on a system-wide basis, or you can install it on a per-user basis. Either way will work the same for the user.

Per User

Assuming you have a ~/bin directory set up added to your $PATH, you can run the following linux command to add Composer to that directory.

$ php composer-setup.php --install-dir=/home/user/bin --filename=composer

System Wide

If you would like Composer to be a available to the entire system, you can install Composer with sudo to the /usr/local/bin directory.

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

Clean Up

Now, clean up the installer. You can wait for it to be removed from /tmp naturally, or run the command below.

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

Closing Thoughts

Now, you can run the composer command to make use of the Composer package manager. If you need a new version of composer you can pass Composer self-update, and it will automatically upgrade itself to the latest available version.