• Time to read 1 minute

Composer is package manager that provides a standard format for application dependency management. Composer is currently distributed in its 2.x series but many applications are still running the 1.x series.

Here is an example of setup that will allow you to switch easily between multiple Composer versions when you are working on multiple applications at the same time.


This tutorial applies to Linux Debian/Ubuntu distributions but should be very similar on other operating systems. You will also need to have PHP 7 running on your machine.

1. Download Composer 2

In order to download composer into the current directory, run the following command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

2. Install Composer 2

Composer can be installed locally in a specific directory. However, in order for a dual setup to work, a global composer installation is required.

From the directory where you downloaded composer, run the following command. This will install composer globally on your server, making it available from any location on the file system:

mv composer.phar /usr/local/bin/composer2

3. Install Composer 1

Composer 1 should also be installed globally with the following command:

# Download composer 1
wget https://getcomposer.org/download/1.10.22/composer.phar

# Set the file permissions
chmod 755 composer.phar

# Give a custom name to the v1 file and install globally
mv composer.phar /usr/local/bin/composer1

You can now run both versions of composer from any folder on your server, using the commands composer1 or composer2. If you want to use the default keyword composer for one of the versions, keep reading.

4. Create symlinks

I'm fine using the composer1 command when I need v1. But as I use the v2 much more often, I'd like to simply run composer instead of composer2 by default. This can be done by creating  a symlink:

ln -s /usr/local/bin/composer2 /usr/local/bin/composer

One last thing...Global version switching

If needed, the Composer version can also be changed globally. Switch from Composer 2 to Composer 1:

composer self-update --1

The other way works, from  from Composer 1 to Composer 2:

composer self-update --2

You now have a dual Composer 1 and Composer 2 set up running on your server, allowing you to work on any application without worrying about versions. Happy composing!