Technical Details

How to Install Composer on Ubuntu / Linux

← Technical Details
2022-05-13 ~ 2026-06-21 · 3 min readTürkçe oku →
How to Install Composer on Ubuntu / Linux
Discuss this article with your AI
Copy page

💡 TL;DR:

  • Goal: Install Composer (the PHP package manager) globally on Ubuntu (20.04 / 22.04 / 24.04 LTS) and Debian-based systems.
  • Pre-requisites: PHP CLI and common extensions (curl, php-cli, php-mbstring, git, unzip) must be installed first.
  • Global Access: Install to /usr/local/bin/composer to allow running the composer command system-wide.

Composer is a popular dependency and package manager used in most PHP projects. If you are a PHP developer, installing Composer is the next step after you install the web and database servers on your development environment. Installing Composer is not that hard on Windows, and the good news is that it is even easier on Ubuntu (tested on Ubuntu 20.04, 22.04, and 24.04 LTS).


Required Packages for Composer on Ubuntu

Package NamePurpose / DescriptionWhy Composer Needs It
php-cliPHP Command Line Interface.Required to run PHP code and Composer scripts in the terminal.
php-mbstringMulti-byte String extension.Handles non-ASCII strings in packages and dependencies.
curlCommand-line tool for transferring data.Used to download the Composer installer script.
gitVersion control system.Downloads packages hosted on GitHub/GitLab directly.
unzipArchive utility for ZIP files.Extracts compressed dependency packages from Packagist.

1. Install PHP and Required Dependencies First

You need to install PHP first if it is not already available on your system.

First, update the package manager's database:

sudo apt update

Next, install PHP CLI and other utilities using the following command:

sudo apt install curl php-cli php-mbstring git unzip -y

2. Download and Verify Composer Installer

Installing Composer is very simple because it provides an installation wizard written in PHP.

Switch to your home directory and download the Composer installer script:

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

To ensure that the installer was not corrupted or modified during download, you can verify its SHA-384 hash using the latest signature from the Composer website:

HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

If it outputs Installer verified, you are safe to proceed.


3. Install Composer Globally

Start the installer using the command below to install Composer globally under /usr/local/bin:

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

The installer will download and install Composer automatically. When you see a message like the one below, then you are done:

All settings correct for using Composer
Downloading...

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

After the installation is complete, clean up the installer script:

rm composer-setup.php

4. Verify the Installation

You can confirm the installation and check the installed version with the following command:

composer --version

And if everything is OK, you will see output similar to this:

Composer version 2.7.7 2024-06-10 22:11:12

Congratulations and happy PHP coding!