Run Composer versions 1 and 2 simultaneously
Composer 2 is great. But it is not compatible with PHP versions lesser then 7.2. So if you're maintaining legacy projects that require older PHP versions, like PHP 7.1, you run into errors like this:
PHP Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.2.0". You are running 7.1.33.
If you want to be able to run Composer 1 and 2 next to each other, you can install them both.
- Install Composer globally, following the instructions from https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos. This will install the latest Composer 2 version in
/usr/local/bin. (on Mac you can simply run
brew install composer)
- Move composer to composer2:
mv /usr/local/bin/composer /usr/local/bin/composer2
- CD to the /usr/local/bin/ folder:
- Download the latest V1 version from https://getcomposer.org/download/1.10.17/composer.phar :
- Make the downloaded phar file executable:
chmod 755 composer.phar
- Rename composer to composer1:
mv /usr/local/bin/composer.phar /usr/local/bin/composer1
- Now create a symlink for the global version you want to use:
ln -s /usr/local/bin/composer1 /usr/local/bin/composer. If you are using a local PHP switcher like
valet, make sure to use composer1 as your global Composer version - otherwise you will get Composer errors if you are on PHP < 7.2.0. If you never run PHP < 7.2.0 locally, you should use Composer 2 as your default.
- To use global Composer: run
- To use global Composer 1: run
- To use global Composer 2: run
That's it. Happy coding!