In just a few steps, you can install the PHP package manager Composer on Ubuntu 20.04. The in­stall­a­tion can be performed on the Linux dis­tri­bu­tion through the terminal.

How to install Composer on Ubuntu 20.04 step by step

In­stalling Composer on Ubuntu 20.04 takes just a few minutes. All you need for the in­stall­a­tion is the Linux Terminal.

Note

If you are not using Ubuntu 20.04, you may find it helpful to check out one of the following articles on in­stalling Composer:

Step 1: update the system

Before getting started with the Ubuntu in­stall­a­tion of Composer, ensure that your system is up to date. To do this, open the terminal and run the following command:

sudo apt update
sudo apt upgrade
bash

You’ll be prompted to enter your password because the above commands are executed with root computers.

Step 2: install required packages

Once you’ve suc­cess­fully updated your system, you can install the packages required for Composer. These include the PHP Command Line Interface and the curl command line utility. If you’ve already installed the required packages on your system, you can skip this step. Otherwise, use this command to begin in­stall­a­tion:

sudo apt install curl php-cli php-mbstring git unzip
bash

Step 3: download and install Composer

To install Composer on Ubuntu 20.04, all you need is a command line command. It’ll use the curl tool you just down­loaded to install the required files for Composer from the official website. Composer will then be installed on your system.

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
bash

After the in­stall­a­tion of Composer is finished, a message will appear in your terminal in­dic­at­ing that the in­stall­a­tion was suc­cess­ful:

Image: Terminal view after installing PHP Composer
Once you’ve finished in­stalling Composer on Ubuntu 20.04, the terminal will let you know and highlight the Composer version you’re using.

Step 4: check in­stall­a­tion

Next, you should manually verify the in­stall­a­tion of Composer by entering the following command:

composer
bash

Finally, you should see a list in the terminal with the most important Composer commands and your current Composer version:

Image: Terminal view after launching PHP Composer
You can launch Composer using the ‘composer’ command and view all the commands that you can run from the package manager.

If running Composer causes any issues on your system, it may be because the folder where you installed Composer (usr/local/bin) is not included in your $PATH en­vir­on­ment variable.

Tip

Did you know that you can use Composer with IONOS web hosting packages? Web hosting from IONOS offers built-in DDoS pro­tec­tion and support for current PHP versions such as PHP 8.

How to add and update de­pend­en­cies in Composer

Once you’ve suc­cess­fully installed the package manager, you can start using the tool and adding de­pend­en­cies to your projects.

Create composer.json file

The composer.json file is where you describe the de­pend­en­cies of your PHP project. You can create the file manually or have it set up auto­mat­ic­ally when you create your first de­pend­ency. For more detailed settings in the composer.json file, it’s best to create it manually using the Composer command:

composer init
bash

Add de­pend­en­cies

The main purpose of Composer is to create and manage de­pend­en­cies in your project. You can add de­pend­en­cies with a single command:

composer require monolog/monolog
bash

In the example above, the logging library Monolog has been added as a de­pend­ency.

Update de­pend­en­cies

Using Composer, you can also update your project’s de­pend­en­cies with the following command:

composer update
bash
Go to Main Menu