As a PHP developer, I find Composer indispensable—it simplifies dependency management and makes it a breeze to work with popular frameworks like Magento 2, Laravel, and CodeIgniter. In this guide, we’ll walk you through the process of installing Composer on Ubuntu 22.04 and 24.04 LTS, ensuring you’re equipped to handle your PHP projects with ease.
What is Composer?
Composer is an application-level dependency manager for PHP. It provides a standardized way to manage the libraries and packages your PHP projects rely on. Developed by Nils Adermann and Jordi Boggiano, Composer has become a cornerstone of modern PHP development.
Prerequisites
To be able to install composer on Linux in general or Ubuntu and Debian in particular, you first need to successfully install PHP and cURL, you can refer to the instructions for install PHP versions. For cURL run the command below if you haven’t already.
sudo apt install curl
Install Composer on Ubuntu 22.04/20.04
Installing the Latest Version of Composer
To install the latest version of Composer on Ubuntu 20.04/22.04, use the following commands:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Installing a Specific (Older) Version of Composer
If you need to install a specific version of Composer to match your framework’s requirements, you can download and install it directly using the terminal with root privileges.
For example, to install Composer version 1.10.26 (required for Magento 2.4.1), you would run the following command (replace 1.10.26 with the version that suits your requirements):
sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer --version=1.10.26
Verifying the Installation
I always make sure to verify my Composer installation by checking its version—this small step has saved me from debugging issues multiple times.
composer --version

This command should display the current version of Composer. If it doesn’t work, your $PATH environment variable may not be configured correctly. In that case, try using the full path:
/usr/local/bin/composer --version
If this works, you may need to add /usr/local/bin
to your $PATH. You can do this by adding the following line to your ~/.bashrc
or ~/.bash_profile
file:
export PATH=$PATH:/usr/local/bin
Then, reload your shell configuration with command:
source ~/.bashrc
# or
source ~/.bash_profile
You have now completed the steps to install Composer on Ubuntu. Personally, I’ve found that using Composer makes PHP dependency management much easier, saving me time and effort in every project.