Composer is the de-facto dependency manager for PHP. It resolves and downloads packages from Packagist, handles autoloading, and manages project-specific dependencies through a composer.json file. This guide installs Composer globally on Ubuntu 26.04 LTS.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS with PHP 8.4 installed
- A user with sudo privileges
- Internet connectivity
Step 1 – Install Required Dependencies
sudo apt update
sudo apt install php8.4-cli php8.4-mbstring php8.4-xml php8.4-curl unzip -y
Step 2 – Download the Composer Installer
cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
Step 3 – Verify the Installer Hash
Verify the installer’s integrity:
HASH=$(curl -sS https://composer.github.io/installer.sig)
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('/tmp/composer-setup.php'); }"
Step 4 – Install Composer Globally
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
Step 5 – Verify the Installation
composer --version
Step 6 – Using Composer
Create a new project:
composer create-project --prefer-dist laravel/laravel myapp
Install a package into an existing project:
composer require guzzlehttp/guzzle
Update all packages:
composer update
Step 7 – Update Composer
sudo composer self-update
Conclusion
Composer is now installed globally on Ubuntu 26.04 LTS. Use it to install PHP frameworks like Laravel and Symfony, or manage any package available on Packagist.org.