49

I want to install old version of composer. My commands are:

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

But it didn't install composer. I check with the command composer -v but unfortunately it didn't work. How can I do this?

space97
  • 153
  • 1
  • 4
  • 19
asma Lri
  • 539
  • 1
  • 4
  • 8
  • If you want to install a specific version & not able to install it in that case you can install a lower version & and then can update it by composer self-update 1.4.1 with specific version – Parvinder Kumar Jul 04 '22 at 05:12

4 Answers4

80

These commands will install composer binary in composer.phar file in current working directory. You may try to verify this by running php composer.phar -v command. composer command will most like point to some global installation in your system - you need to move new binary to correct place, so it could be recognized as global command (see docs):

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

If you have already Composer installed, you should able to use self-update command to downgrade to any version:

composer self-update 1.4.1

or

sudo -H composer self-update 1.4.1
rob006
  • 21,383
  • 5
  • 53
  • 74
  • 1
    I install the latest version of composer then change to the version 1.4.1 with the command composer self-update 1.4.1 and it worked thank you – asma Lri Dec 14 '19 at 23:32
  • 3
    I've got problem with compose 2.0 when my project was running successfully at version 1.8.0. Use "composer self-update [version]" solves the problem. Really a paint like unexpected errors happen from no-where. – Tuananhcwrs Oct 24 '20 at 18:33
  • 5
    This is definitely the way it seems to change composer version. Although I have installed version 1 with the folowing: `curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=1.10.16` – Ethan Knowlton Oct 27 '20 at 20:10
  • 1
    composer self-update 1.4.1 this will break the composer and it starts throwing error [ErrorException] Trying to access array offset on value of type null – Vinit Kadkol Nov 04 '20 at 10:04
  • 6
    `1.4.1` is pretty old, it probably won't work on latest PHP. If you just want to go back to 1.x line, use `composer self-update --1` (or `composer self-update 1.10.17` if your composer does not support `--1` flag). – rob006 Nov 04 '20 at 10:09
  • composer self-update --rollback to roll back to original version. – b.doe Feb 10 '21 at 13:26
34

If you came here searching for downgrading from composer 2.0 to 1.0

composer self-update --1

goellner
  • 493
  • 5
  • 10
26

Curl can be used to download a specific version:

curl -O "https://getcomposer.org/download/1.10.17/composer.phar"
chmod a+x composer.phar
sudo mv composer.phar /usr/local/bin/composer
Amadu Bah
  • 2,919
  • 28
  • 27
8

If you have installed composer v2, and want to install composer v1 in addition you can do:

wget https://getcomposer.org/composer-1.phar
chmod a+x composer-1.phar
sudo mv composer-1.phar /usr/local/bin/composer1

And use composer1 on old projects:

cd <OLD-PROJECT>
composer1 install