Install Composer on Ubuntu 20.04

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.

Prepare environment

Before starting, make sure you have installed PHP in the system. You can read post how to install it.

Install Composer

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 composer command.

We can check Composer version as follows:

composer --version

Composer installer is no longer needed, you can remove it:

rm -rf composer-setup.php

Update Composer

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

Uninstall Composer

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

Leave a Comment

Your email address will not be published. Required fields are marked *