Question

How to install composer 2

Hello

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-20-04

how to upgrade to version 2 ?? command, composer self-update --2 , is not defined !!

Also as non root user: file_put_contents(/var/www/mywebsite/vendor/composer/autoload_classmap.php): failed to open stream: Permission denied.

Regards, Tjeu


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
April 15, 2021
Accepted Answer

Hi there,

In case that you’ve installed composer with apt already you might have to remove the package first and then follow the steps from the tutorial:

  • Remove the current installation:
sudo apt remove composer
  • Install the latest version:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"

Let me know how it goes. Regards, Bobby

  1. Uninstall composer:
sudo apt-get remove composer

stackoverflow.com/questions/30396451/remove-composer

  1. Install Composer:
cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-22-04

The previous solution (from 15 April 2021) will no longer work.

See instructions on the Composer Download page (and the warning “Please do not redistribute the install code. It will change with every version of the installer.”)

https://getcomposer.org/download/

This worked for me to install Composer version 2.3.9 today in my droplet.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel