Composer version 2 has been available quite some time now and it’s great! Yes, but… version 2 is only compatible with PHP versions from 7.2 and up. This can be troublesome if you’re running projects that still depend on PHP 7.1 or older. You might bump into errors like;
You are using Composer 2, which some of your plugins seem to be incompatible with. Make sure you update your plugins or report a plugin-issue to ask them to support Composer 2.
But, good news is here. You can run Composer version 1 and 2 simultaneously on your system with minimal effort. On a Mac I’ve achieved this with the following steps.
I already had Composer installed before in the following path.
/usr/local/bin/composer.phar
Also, I had the following alias in ~/.bash_profile
to prevent annoying out of memory errors when running composer install
commands.
alias composer="php -d memory_limit=-1 /usr/local/bin/composer.phar"
I updated this version to the latest with the following command. If you’re still on version 1 here, you’ll notice after the update you’ll be running version 2.
composer self-update
Which gave me (at time of writing) the following version.
composer --version
> Composer version 2.0.13 2021-04-27 13:11:08
At this point I downloaded the latest of version 1 with the following command. Note: it doesn’t matter in which path you are at time of downloading.
curl --silent --show-error https://getcomposer.org/installer | php -- --version=1.10.22
This downloads the file composer.phar
in you’re current path. I moved this (and made it executable at the same time).
mv composer.phar /usr/local/bin/composer1.phar
For this version 1 I also created an alias.
alias composer1="php -d memory_limit=-1 /usr/local/bin/composer1.phar"
And running a version check verifies it.
composer1 --version
> Composer version 1.10.22 2021-04-27 13:10:45
… and you’re done!