Update composer from command line

Posted on

In this article, there is a need to update composer which is a dependency manager for PHP. This is happened when laravel framework-web based project is going to be created.

In the first step, the command executed is to diagnose the composer whether it is reliable to be used or not :

composer.php diagnose

The output of the above command can be described as follow :

user@hostname:~$ composer.phar diagnose
Warning: This development build of composer is over 60 days old. It is recommended to update it by running "/usr/bin/composer.phar self-update" to get the latest version.
Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Authentication required (packagist.org):
Username:
Password:
FAIL
[Composer\Downloader\TransportException] Invalid credentials for 'http://packagist.org/packages.json', aborting.
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking composer version: FAIL
You are not running the latest version
user@hostname:~$ 

The output of the above command is clearly stated in the message ” You are not running the latest version “. In order to update it to the latest one, below is the execution of the command for updating composer :

user@hostname:~$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Authentication required (packagist.org):
Username:
Password:
Invalid credentials for 'http://packagist.org/p/provider-2013%2429ae60b62e12d7e5d86427c4b8a56951a90b38cb2b3f7d678099bc8c48f7af49.json', aborting.
http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
[Composer\Downloader\TransportException]
Invalid credentials for 'http://packagist.org/p/sebastian/code-unit-reverse-lookup%249a0ac7a79098bd12fcb877e4cd2dec96bbf6d7087c72078b9707319004b42154.json', aborting.
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]...
user@hostname:~$

Try to re-execute the command of diagnosing composer by executing ‘composer diagnose’ :

user@hostname:~$ composer diagnose
Checking composer.json: OK
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: Warning: Accessing packagist.org over http which is an insecure protocol.
Authentication required (packagist.org):
Username:
Password:
FAIL
[Composer\Downloader\TransportException] Invalid credentials for 'http://packagist.org/packages.json', aborting.
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: FAIL
You are not running the latest stable version, run `composer self-update` to update (1.2.0 => 1.2.1)
user@hostname:~$ 

In the above execution of ‘composer diagnose’ there are explicit information regarding the neccessity of updating composer. It is because the current version is 1.2.0 and it need to be updated to 1.2.1 by executing the command ‘composer self-update’. Below is the execution of the command :

user@hostname:~$ composer self-update
Updating to version 1.2.1 (stable channel).
Downloading: 100%
[ErrorException]
rename(/home/user/.composer/cache/composer-temp.phar,/usr/local/bin/composer): Permission denied
self-update [-r|--rollback] [--clean-backups] [--no-progress] [--update-keys] [--stable] [--preview] [--snapshot] [--] [<version>]
user@hostname:~$

Since there are several errors popped out from the several command execution above as follows :

a. The execution of composer update is not valid and it is suggested to run `composer self-update`
b. The execution of composer update is denied since the user doesn’t have any permission to rename the composer file

Below are steps which is done to resolve the above problems :

1. Switch to root user by typing the following command :

sudo su -

The output’s execution is shown below :

user@hostname:~$ sudo su -
[sudo] password for user:
root@hostname:~#

2. Execute the appropriate command to update the composer’s version by executing the following command :

composer self-update

The output can be seen as follow :

user@hostname:~# composer self-update
Updating to version 1.2.1 (stable channel).
Downloading: 100%
Use composer self-update --rollback to return to version 1.2.0
user@hostname:~#

 

Last but not least, check the version of the composer by executing the following command :

composer --version

Below is the command execution in a bash prompt :

user@hostname:~# composer --version
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Composer version 1.2.1 2016-09-12 11:27:19
root@hostname:~#
user@hostname:~$ composer --version
Composer version 1.2.1 2016-09-12 11:27:19
user@hostname:~$

 

Leave a Reply