Install PHP Composer on Ubuntu

How to Install PHP Composer on Ubuntu 18.04 / 20.04

In this tutorial, we have managed to share How to install PHP Composer on Ubuntu 18.04 and Ubuntu 20.04.

Composer is a dependency manager for PHPComposer will manage the dependencies you require on a project by projects / applications basis.

Most of the PHP applications require you to have Composer installed on your system in order to get the package installed and working.

Modern PHP applications require several external packages, imagine having over 15 requires and 15 autoloading functions. terrible!

Modern PHP applications require several external packages, imagine having over 15 requires and 15 autoloading functions. terrible!! This is where Composer comes to help.

Composer handles autoloading automatically, you just have to write the following line of code which will allow you to load all your referenced packages:

Composer solves the following problems:

  • dependency resolution for PHP packages
  • autoloading solution for PHP packages
  • keeping all packages updated

You may also like : How to Install Postman on Ubuntu 18.04 / 20.04

To run Composer you should have PHP installed. So when you are ready follow the below steps to get Composer installed on your system.

Step 1: Install PHP

Composer requires PHP 5.3 or higher.. to install PHP on Ubuntu, run the commands below

sudo apt install php

If you need to install other versions of PHP that’s not available in Ubuntu default repositories for your system, run the commands below to install a third-party repository which contains PHP 7.2, 7.3, 7.4 and up.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Now simply run the commands below to install PHP 7.4… change the number value to install 7.2, 7.3 and so forth.

sudo apt install php7.4

Step 2: Install Compser

Now that PHP is installed.. you can now run the commands below to install Composer

curl -sS | sudo php -- --install-dir=/usr/local/bin --filename=composer

The commands above will download Composer from its maintainer page and install it into the /usr/local/bin directory… this is a local global directory for application executables…

All settings correct for using Composer

Composer (version 1.6.4) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Now simply run the commands below to test whether Composer is installed.


The output should look like something below

  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer version 1.6.4 2018-04-13 12:04:24

  command [options] [arguments]

  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Composer can also be upgraded by running the commands below.. this will upgrade all packages associated with Composer.

sudo composer self-update

That’s it you have successfully installed Composer on your system.

Updating Dependencies

To update all the dependencies in your composer.json file enter the command:

composer update

This will update all dependencies according to the version specified in the file.

To update one (or more) dependencies individually:

composer update vendor/package vendor_b/package_b


Now you have a good understanding of how to install and start using PHP Composer.

Follow TechBiriyani on FacebookTwitter to get all the latest updates.

Leave a Reply

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