How to Install Composer on Ubuntu 18.04 Bionic Beaver

Install Composer on Ubuntu 18.04

In this article, we will have explained the necessary steps to install and configure Composer on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Composer is a best dependency manager for PHP. Composer can install, update and pull in all the required PHP packages to your project directory. At the time of installing package, composer will check for dependencies of package and if dependent package are there then it will also install dependencies.

Install Composer on Ubuntu

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade
sudo apt install wget php-cli php-zip unzip

Step 2. Install Composer.

Now that we have php cli installed on our machine, we can download the composer installer with:

php -r "copy('', 'composer-setup.php');"

File composer-setup.php will be downloaded to current working directory. After that, check the data integrity of the script by comparing the script SHA-384 hash on the Composer Signatures page.

HASH="$(wget -q -O -"

Now run the following command to verify that the installation script is not corrupted:

php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

You will get following output if the hashes match:

Installer verified

Next, the following command will install Composer in the /usr/local/bin directory:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

It will show you output as below:

All settings correct for using Composer

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

At last, you can verify the installation by typing:


The command above, will print the Composer’s version, commands and arguments:

/ ____/___  ____ ___  ____  ____  ________  _____
/ /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer version 1.8.5 2019-09-23 16:46:47

    command [options] [arguments]

That’s all you need to do to install Composer on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.