Unable to self-update composer?

It worked for me (linux, Ubuntu 20.04):

sudo apt-get remove composer
sudo apt-get update
sudo apt-get install curl
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Install the latest version:

Remove your current Composer version, for example Ubuntu/Debian:

sudo apt-get remove composer

Now, head to https://getcomposer.org/download/ and paste the script in your command line. This ensures that you get the latest version of Composer (as time of writing: v2.0.7).

Like this:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"

After some time passed, you can update and there isn't any need to use the sudo prefix:

composer self-update

As Waqleh said, you have to uninstall PHP Composer and install it again. First, execute:

sudo apt-get remove composer

Then, execute these commands. The checksum here is for Composer 1.10.13, but you'll get the newest Composer (2.0.4 at the moment of editing this answer) when running the first line, so be sure to check in https://getcomposer.org/download/:

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

Now move file composer.phar to a directory that is in your path (from Installation - Linux / Unix / macOS):

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

And execute composer from any directory. That's all!

PS: If you're using PhpStorm (or maybe other IDEs), you'll have to close it and open it again.


Since I posted my answer, I have learnt a new easier way to install Composer programmatically: How do I install Composer programmatically?

Old Answer:


As per @JimL comment, I was able to self update Composer by:

  • Uninstalling Composer from the package manager (apt).
  • I installed it according to the official documentation

Now it works as expected.