I am trying to update composer with no luck!
What I have tried:
$ composer self-update
[InvalidArgumentException]
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') === 'c31c1e292ad7be5f49291169c0ac8f683499effffdcfd4e42232982d0fd193004208a58ff6f353fde0012d35fdd72bc394') { 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 no need to use sudo prefix:
composer self-update
As @Waqleh said, you have to uninstall 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 composer.phar to a directory that is in your path (fom https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx):
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 IDE's) you'll have to close it and open again.
As per @JimL comment I was able to self update composer by:
Now it works as expected.
you can specify installation directory and filename while setting up composer - php composer-setup.php
like so:
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
I've installed brew and it saves me a lot.
Install brew then brew install composer
to install the composer.
Uninstalling Composer
sudo apt-get remove composer
Run following commands
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
Install Composer in /usr/bin dir to run composer from anywhere
sudo php composer-setup.php --install-dir=/usr/bin --filename=composer
Remove the installer
php -r "unlink('composer-setup.php');"
To check or self update
composer self-update