Usually, I execute the following command to upgrade the composer version, but I found an error.
ubuntu@localhost:~$ composer self-update --2
[sudo] password for ubuntu:
Command “self-update” is not defined
First of all check your composer’s version, as I have shown below
ubuntu@localhost:~$ composer -V
Composer 1.6.3 2018-01-31 16:28:17
I’m working with the old version of the composer, That’s why I’m getting the error.
After checking this error I found that the command is not available on the previous old versions of the composer, So I removed the old composer completely and reinstalled version 2.
For this I executed the following commands:
Remove the old version 1.6 of the composer.
ubuntu@localhost:~$ sudo apt-get remove composer
If you are getting an error then please do it with the following command
ubuntu@localhost:~$ sudo rm -rf /usr/local/bin/composer
Install the latest version of Composer:
First, update the package manager cache by running the “update” command and installing the required packages
ubuntu@localhost:~$ sudo apt update
install the required packages
ubuntu@localhost:~$ sudo apt install php7.*-cli unzip
You can replace the * with your installed PHP version, like php7.4 or 8.0
ubuntu@localhost:~$ cd ~
ubuntu@localhost:~$ curl -sS https://getcomposer.org/installer -o composer-setup.php
Now open the following link and copy the “Installer Checksum (SHA-384)” HASH.
URL: https://composer.github.io/pubkeys.html
ubuntu@localhost:~$ HASH=55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae
After this please execute the following PHP code.
ubuntu@localhost:~$ php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Now you’ll get the output like:
“Installer verified”
The final step is to install the composer globally.
buntu@localhost:~$ sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
The installation has been done, now you can verify composer installation with the following command.
ubuntu@localhost:~$ composer
If you have skills in PHP programming and you want to enhance your career in this field, a PHP certification from StudySection can help you reach your desired goals. Both beginner level and expert level PHP Certification Exams are offered by StudySection along with other programming certification exams.