How To Install Composer on Ubuntu 20.04

Published on  

3 min read

Looking for other version?

Choose a different version or distribution.

How To Install and Use Composer on Ubuntu 20.04

In this guide, we will walk you through the steps to install Composer on Ubuntu 20.04

Composer is a popular dependency manager for PHP, and it is used by many developers to manage their PHP projects.

It is used in popular PHP CMS and Frameworks like Magento and Laravel to manage its components and dependencies. The composer makes use of a composer.json file to specify version and dependency information. In this tutorial, you'll install Composer on Ubuntu 20.04. Let's get started.

Prerequisites

  • A server with Ubuntu 20.04 as OS
  • User privileges: root or non-root user with sudo privileges

System Requirements

Composer in its latest version requires PHP 7.2.5 to run. A long-term-support version (2.2.x) still offers support for PHP 5.3.2+ in case you are stuck with a legacy PHP version. A few sensitive php settings and compile flags are also required, but when using the installer you will be warned about any incompatibilities.

Step 1: Update Your System

Before we begin, let's make sure that our system is up to date. Open a terminal window and run the following command:

sudo apt update && sudo apt upgrade

This command will update the package list and upgrade any outdated packages on your system.

Step 2: Install PHP

Composer is written in PHP, so you'll need to have PHP installed on your system before you can install Composer. Run the following command to install PHP:

sudo apt install php

If you already have PHP installed in your system you can skip this step.

Step 3: Install Dependencies

Start by updating your package manager cache and installing the required dependencies, including php-cli:

sudo apt install php-cli unzip

Step 4: Install Composer

Now that we have PHP installed, we can install Composer using curl. Run the following commands to download and install Composer:

cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php

The following command will download and install Composer as a system-wide command named composer, under /usr/local/bin:

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

Step 5: Verify the Installation

Once the installation is complete, you can verify that Composer is installed by running the following command:

composer --version

If Composer is installed correctly, you should see the version number printed in the terminal.

Conclusion

In this guide, we walked you through the steps to install Composer on Ubuntu 20.04. Composer is a powerful tool that can help manage your PHP dependencies and streamline your PHP development workflow. If you're interested in learning more about Composer, check out the official Composer website.

About the Author

Rexposed Staff

Was this helpful?