Composer is a dependency management tool for PHP which enables to specify libraries on which project depends on. Composer manages libraries installation and update per-project (the default) or globally.
This tutorial demonstrates how to install Composer on Ubuntu 20.04.
Before starting, make sure you have installed PHP in the system. You can read post how to install it.
Run the following command to download Composer installer:
wget -O composer-setup.php https://getcomposer.org/installer
Next, install Composer globally as a system-wide command:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Composer was installed under
/usr/local/bin directory and it will be available for all users as
We can check Composer version as follows:
Composer installer is no longer needed, you can remove it:
rm -rf composer-setup.php
The following command can be used to update Composer to the latest version:
sudo composer self-update
If you decided to downgrade Composer to the latest 1.x version, run the following command:
sudo composer self-update --1
Execute the following command if you want to upgrade Composer to the latest 2.x version:
sudo composer self-update --2
It is also possible to update Composer to a specific version:
sudo composer self-update 1.10.19 sudo composer self-update 2.0.8
If you want to remove Composer, you need to remove Composer command itself and all related directories.
sudo rm -rf /usr/local/bin/composer sudo rm -rf /root/.composer sudo rm -rf /root/.cache/composer sudo rm -rf /root/.local/share/composer sudo rm -rf /root/.config/composer rm -rf ~/.cache/composer rm -rf ~/.local/share/composer rm -rf ~/.config/composer