Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to self-update Composer

I am trying to update Composer without any luck!

What I have tried:

$ composer self-update 

[InvalidArgumentException] Command "self-update" is not defined.

$ sudo -H composer self-update 

[InvalidArgumentException] Command "self-update" is not defined.

$ sudo apt-get install composer 

Reading package lists... Done Building dependency tree Reading state information... Done composer is already the newest version. The following packages were automatically installed and are no longer required: libntdb1 linux-headers-4.2.0-30 linux-headers-4.2.0-30-generic linux-image-4.2.0-30-generic linux-image-extra-4.2.0-30-generic python-ntdb Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.

I am trying to self-update Composer because I am facing the following each time I try:

$ composer update 

Loading composer repositories with package information Updating dependencies (including require-dev) [RuntimeException] Could not load package rmrevin/yii2-fontawesome in http://packagist.org: [UnexpectedValueException] Could not parse version constraint v4.1 .: Invalid version string "v4.1." [UnexpectedValueException] Could not parse version constraint v4.1.: Invalid version string "v4.1."

How can I fix this issue?

My PHP version is:

php --version 

PHP 5.6.11-1ubuntu3.4 (cli) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

My composer version is:

composer --version 

Composer version @package_branch_alias_version@ (@package_version@) @release_date@

like image 845
Waqleh Avatar asked Jun 12 '16 09:06

Waqleh


People also ask

Can not update composer?

Try clearing Composer's cache by running composer clear-cache . Ensure you're installing vendors straight from your composer. json via rm -rf vendor && composer update -v when troubleshooting, excluding any possible interferences with existing vendor installations or composer.

How do I update the composer to the latest version?

update / u# In order to get the latest versions of the dependencies and to update the composer. lock file, you should use the update command.

How do I update the composer to the latest version of Ubuntu?

To change to version one, run the self-update command and pass in the --1 flag. This will change the composer to version one, and now you can install your dependencies. Once you have installed your dependencies, you can now run the same command and pass in --2 as the flag, which will switch back to composer version 2.


1 Answers

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.

like image 143
Manolo Avatar answered Sep 28 '22 02:09

Manolo