How To Install Composer on Ubuntu 22.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

This guide will help you through installing Composer on Ubuntu 22.04 (Jammy Jellyfish).

Composer is a popular PHP dependency manager that many developers use to manage their PHP applications.

It is used to handle the components and dependencies of popular PHP CMS and Frameworks such as Magento and Laravel. A composer.json file is used by the composer to specify version and dependency information. Composer will be installed on Ubuntu 22.04 (Jammy Jellyfish) in this tutorial. Let's get this party started.

Prerequisites

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

System Requirements

Composer's most recent version requires PHP 7.2.5 to function. If you're trapped with a legacy PHP version, a long-term-support version (2.2.x) still supports PHP 5.3.2+. A few critical php settings and compilation flags are also necessary, although you will be notified about any incompatibilities while running the installer.

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

We led you through the steps to install Composer on Ubuntu 22.04 (Jammy Jellyfish) in this post. Composer is a useful tool for managing PHP dependencies and streamlining 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?