Composer is the dependency manager for PHP, similar to npm for Node.js or Bundler for Ruby. You list the libraries your project needs in a composer.json file, and Composer downloads them, along with everything they depend on, with a single command. It also generates an autoloader, so you don’t have to include each library by hand.
This tutorial shows you how to install the latest Composer (2.11 at the time of writing) on Ubuntu 26.04 LTS and Ubuntu 24.04 LTS using the official installer, verify the download, test it with a small project, and keep it up to date.
Prerequisites
- A running Ubuntu 26.04 or 24.04 system and a user with
sudoprivileges. - PHP 7.2.5 or newer, the minimum for current Composer releases. Ubuntu’s own PHP is new enough: Ubuntu 26.04 ships PHP 8.5 and Ubuntu 24.04 ships PHP 8.3. For other versions, see How to Install PHP 8.5 on Ubuntu 26.04 or How to Install PHP on Ubuntu 24.04.
Step 1 of 5Install PHP CLI and Required Tools
Composer runs on the PHP command line. It also needs unzip (or the PHP zip extension) to extract packages, and git for packages installed from source. Update the package index and install them:
sudo apt updatesudo apt install php-cli php-zip php-curl php-mbstring unzip curl git -y
Check the PHP version:
php -v
You should see PHP 8.5 on Ubuntu 26.04 or PHP 8.3 on Ubuntu 24.04. If you installed PHP from another source, any version from 7.2.5 up works.
Step 2 of 5Download and Verify the Composer Installer
Move to your home directory and download the installer script:
cd ~curl -sS https://getcomposer.org/installer -o composer-setup.php
Before running it, check that the file wasn’t corrupted or tampered with. Composer publishes the installer’s SHA-384 checksum at composer.github.io/installer.sig. It changes with every new installer, so always fetch it fresh instead of copying a hash from a tutorial:
HASH="$(curl -sS https://composer.github.io/installer.sig)"php -r "if (hash_file('sha384', 'composer-setup.php') === '$HASH') { echo 'Installer verified' . PHP_EOL; } else { echo 'Installer corrupt' . PHP_EOL; unlink('composer-setup.php'); exit(1); }"
If you see Installer verified, continue. If you see Installer corrupt, the script has been deleted: download it again and repeat the check.
Step 3 of 5Install Composer Globally
Run the installer and place the composer command in /usr/local/bin, so every user on the system can run it from any directory:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
The installer downloads the latest stable release and prints a message like Composer (version 2.11.2) successfully installed to: /usr/local/bin/composer. Remove the installer script, as it’s no longer needed:
rm composer-setup.php
Confirm that Composer works:
composer --version
The output shows the Composer version and the PHP version it runs on. Run composer without arguments to see the list of available commands, or composer diagnose to check your setup for common problems.
Installing from the Ubuntu repository instead: Ubuntu also packages Composer, and you can install it with
sudo apt install composer. The packaged version is older (2.9 on Ubuntu 26.04 and 2.7 on Ubuntu 24.04), only gets security fixes, and can’t be updated withcomposer self-update. Use the official installer above if you want the current release.
Step 4 of 5Test Composer with a Sample Project
Run Composer as your regular user, not with sudo: running it as root lets package scripts run with full system rights, and Composer warns you about it (see Composer: Continue as Root/Super User).
Create a project directory and add a library, for example the Monolog logging library:
mkdir ~/composer-demo && cd ~/composer-democomposer require monolog/monolog
Composer creates three things in the directory:
- composer.json: lists the packages your project requires.
- composer.lock: records the exact installed versions, so every install of the project gets the same ones.
- vendor/: holds the downloaded packages and the autoloader, vendor/autoload.php.
To use the library, include the autoloader in your code. Create a file named app.php:
<?php
require __DIR__ . '/vendor/autoload.php';
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$log = new Logger('demo');
$log->pushHandler(new StreamHandler('php://stdout'));
$log->info('Composer is working!');
Run it:
php app.php
You should see a log line like [2026-11-14T10:30:00.000000+00:00] demo.INFO: Composer is working! [] []. When you copy a project to another machine, run composer install in its directory to install the exact versions from composer.lock. To learn more, see Managing Dependencies with Composer.
Step 5 of 5Update Composer
Composer can update itself. Because it is installed in /usr/local/bin, run the update with sudo:
sudo composer self-update
If a new release causes problems, go back to the previously installed version:
sudo composer self-update --rollback
Note: Projects stuck on PHP older than 7.2.5 can’t run current Composer releases. For those, the Composer 2.2 LTS branch (
sudo composer self-update --2.2) still supports PHP 5.3 and up, but it only receives critical security fixes, until 31 December 2026. Upgrading PHP is the better long-term fix. To run Composer with a specific PHP version, see Using Composer with Different PHP Versions in Linux.
Uninstall Composer
To remove Composer, delete the binary. You can also delete its configuration and cache directories in your home directory:
sudo rm /usr/local/bin/composerrm -rf ~/.config/composer ~/.cache/composer
This doesn’t touch your projects: their vendor/ directories stay where they are.
Conclusion
You have installed the latest Composer on Ubuntu 26.04 or 24.04 with the official installer, verified the download, and used it to add a library to a project. Keep it current with sudo composer self-update, run it as a regular user, and commit both composer.json and composer.lock to version control so everyone working on the project gets the same dependencies.
How did it make you feel?

Now its working.
Thanks
still works tnx.
i don’t have directory “bin” in usr/local/, instead there is a directory “sbin”.
what should i do?
it worked for me, thanks
wow.i love your posts.
Thank You Very Much
Thank you!
Thk u dude this is ok tuto!
Thanks
Thanks !!!
Thanks you!