Learn how to install Composer on Linux using the official method. Follow simple step by step instructions to download, verify, install, update, and use Composer for PHP projects.
Composer is the most popular dependency manager for PHP. It helps you install libraries, manage project packages, and keep your PHP applications organized. Whether you are working with Laravel, Symfony, WordPress, or a custom PHP project, Composer is an essential tool.
This guide shows you how to install the latest version of Composer on any Linux distribution using the official installation method.
Prerequisites
Before installing Composer, make sure your system has:
- A Linux server or desktop
- PHP 7.2.5 or later installed
- Internet access
- A user account with sudo privileges
You can check your PHP version with:
php -v
If PHP is installed, you will see its version information.
Step 1: Update Your System
Start by updating your package list.
Ubuntu and Debian
sudo apt update
Rocky Linux, AlmaLinux, CentOS Stream, and Fedora
sudo dnf update
Step 2: Install Required Packages
Install the tools needed to download and verify Composer.
Ubuntu and Debian
sudo apt install curl php-cli php-mbstring php-zip unzip -y
Rocky Linux, AlmaLinux, CentOS Stream, and Fedora
sudo dnf install curl php-cli php-mbstring php-zip unzip -y
Step 3: Download the Composer Installer
Download the official Composer installer.
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
This command saves the installer as composer-setup.php.
Step 4: Verify the Installer
Verify the installer before running it.
php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
If everything is correct, you will see:
Installer verified
The official Composer website updates this verification hash whenever needed, so always use the latest value from the download page.
Step 5: Install Composer Globally
Run the installer and place Composer in /usr/local/bin.
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
You should see output similar to:
Composer successfully installed
Step 6: Remove the Installer
Delete the installer file after installation.
rm composer-setup.php
Step 7: Verify the Installation
Check that Composer is installed correctly.
composer --version
Example output:
Composer version 2.x.x
This confirms Composer is ready to use.
Create Your First PHP Project
Move to your project directory.
cd /path/to/your/project
Initialize Composer.
composer init
Follow the prompts to create a composer.json file.
Install a PHP Package
To install a package, use the require command.
For example:
composer require monolog/monolog
Composer downloads the package and creates a vendor directory automatically.
Install Existing Project Dependencies
If your project already contains a composer.json file, install all required packages with:
composer install
This downloads every dependency listed in the project.
Update Installed Packages
To update all project packages:
composer update
Update Composer
To install the latest stable version of Composer itself:
sudo composer self-update
This updates Composer to the newest available release.
Uninstall Composer
If you want to remove Composer from your system:
sudo rm /usr/local/bin/composer
Conclusion
You have successfully installed Composer on Linux using the official installation method. Composer is now available from any terminal session, making it easy to manage PHP packages and project dependencies. Whether you are building a Laravel application, a WordPress plugin, or a custom PHP project, Composer provides a simple and reliable way to keep your development environment organized.

