Install PHP Composer on Ubuntu

From WikiMLT

Up­date 2022

The in­struc­tions be­low may be dep­re­cat­ed! Be­cause the in­struc­tions will change with every ver­sion of the in­staller… In­stead, please vis­it the page https://​getcomposer​.org/​d​o​w​n​load/ and fol­low the steps pro­vid­ed there!

If Com­pos­er is al­ready in­stalled on your sys­tem – i.e. /​​​usr/​​​local/​​​bin/​​​composer – you can up­date it by the fol­low­ing com­mand com­mand :

sudo composer self-update
Upgrading to version 2.5.1 (stable channel).
Use 'composer self-update --rollback' to return to version 2.4.4

In­stall the lat­est ver­sion of Com­pos­er

sudo apt update
sudo apt install php-cli unzip
cd ~/tmp && \
curl -sS https://getcomposer.org/installer -o composer-setup.php && \
HASH=$(curl -sS https://composer.github.io/installer.sig) && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { 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 && \
composer -V

Ref­er­ences

In­stall Com­pos­er via Apt

sudo apt update && \
sudo apt install composer

De­pend­ing on the ver­sion of the OS the Composer's ver­sion could be rel­a­tive­ly old.