Ideally, the PHP package manager Composer can update itself with the command
composer self-update
Unfortunately, when I ran this command I got
[RuntimeException]
SHA384 is not supported by your openssl extension, could not verify the phar file integrity
This is a known issue (see Composer Issue 7669) but unfortunately the thread does not offer a clear solution.
How I Upgraded Composer
I’m on a Mac running macOS Mojave (10.14
), here is how I worked around this RuntimeException and upgraded my version of Composer.
Find Composer’s Location
To find the location of your current (out-dated) version of Composer, run
type composer
composer is hashed (/usr/local/bin/composer)
Take note of the composer location (in my case /usr/local/bin/composer
), this will be important in a moment.
Run the Initial Composer Install
From the command line, run the Composer install command (as documented at Download Composer).
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
This displayed the message
Composer (version 1.9.0) successfully installed to: /Users/sal/composer.phar
Use it: php composer.phar
Make note of the new installation path (in my case /Users/sal/composer.phar
), this will also be important in a moment.
Move the New Version to the Correct Location
From the command line you’re going to move (mv
) the new installation path (in my case /Users/sal/composer.phar
) to the composer location (in my case /usr/local/bin/composer
). Here is the command I ran
mv /Users/sal/composer.phar /usr/local/bin/composer
Check the Change Occurred
By running
composer --version
you should now see the latest version of the Composer.
Thanks
This post originally came about during my Five for the Future (5ftf) work at WebDevstudios. Thank you, WebDevStudios.
Hey Sal, thanks for sharing this!
Hate it when a simple update doesn’t work 🙂
Cheers
Thanks for the post Sal. This worked perfectly!
Thank you Sal,
I am searching this solution for last 30min. I don’t imagine that it is so simple. I just have to move the new composer.phar to the old location.