This is an article which is specifically made to show how to update the version of a composer. The update process described is done in Linux operating system executed as a specific command in a command line interface. The most important thing is to have the composer installed so that obviously it can be updated.
First of all, to update the version of a composer, it is important to check the HTTP connectivity first. To be able to do that, read the article titled ‘Composer Checking HTTP Connectivity’ which can be found in this link.
After successfully find out that composer doesn’t have any problem with HTTP connectivity, the process in order to update the version of the composer can be done.
To initiate the process of updating composer’s version, how does someone really know that the current version of a composer installed in the laptop or PC is not update ?, the answer is actually given when the composer itself is being executed for HTTP connectivity diagnosis. If the current installed composer’s version is not update the output of the command ‘composer diag’ executed in the command line will be shown as follows :
user@hostname:~$ composer diag Checking composer.json: OK Checking platform settings: OK Checking git settings: OK Checking http connectivity to packagist: OK Checking https connectivity to packagist: OK Checking github.com rate limit: OK Checking disk free space: OK Checking pubkeys: Tags Public Key Fingerprint: XXXXXX XXXXXXX XXXXXXXXX XXXXXXX XXXXXXX XXXXXXX XXXXXXXXX XXXXXXXXX Dev Public Key Fingerprint: XXXXXXXX XXXXXX XXXXXXX XXXXXXX XXXXXX XXXXXXXX XXXXXXXX XXXXXXXX OK Checking composer version: WARNING You are not running the latest stable version, run `composer self-update` to update (1.2.1 => 1.3.2) usr@hostname:~$
As informed in the above output of the executed command for checking HTTP connectivity, there is a WARNING regarding on composer version. So, start updating the version of the composer which is instructed in the output of the command by executing or typing ‘composer self-update’ in the command line. Below is the command :
This is the output of the command executed if the connection is not available or the HTTP connectivity is poor :
user@hostname:~$ [Composer\Downloader\TransportException] The "https://getcomposer.org/versions" file could not be downloaded: failed to open stream: Network is unreachable self-update [-r|--rollback] [--clean-backups] [--no-progress] [--update-keys] [--stable] [--preview] [--snapshot] [--] [<version>] user@hostname:~$
On the other hand, below is actually the output represent what will happen if the user executed the command for updating the version doesn’t have enough privilege to do it :
user@hostname:~$ composer self-update Updating to version 1.3.2 (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:~$
So, in order to update the version by executed the command properly, switch to another user whom has enough privilege to do that. Below in linux operating system there is a way to do it :
user@hostname:~$ sudo su - [sudo] password for user: root@hostname:~#
After successfully switch to ‘root’ user which is done to be able to execute the update composer’s version properly, run the command :
root@hostname:~# composer self-update Updating to version 1.3.2 (stable channel). Downloading: 100% Use composer self-update --rollback to return to version 1.2.1 root@hostname:~#
Last but not least, check the version of the composer whether it is already updated or not :
user@hostname:~$ composer --version Composer version 1.3.2 2017-01-27 18:23:41 user@hostname:~$
Based on the output above, the version of the composer has already been updated.