
Composer is the standard PHP dependency manager, and Install Composer on Ubuntu 26.04 the right way matters if you want a clean, reliable setup. In this guide, I will show you how to install it safely, verify the installer, and confirm that it works on a modern Ubuntu system. The steps below are written for beginners and intermediate users, but they follow the same practical approach a sysadmin would use on a real server.
Introduction
If you work with PHP, you will eventually need Composer. It handles packages, updates, and autoloading so you do not have to manage libraries by hand. That saves time and reduces setup mistakes.
This tutorial focuses on a secure Install Composer on Ubuntu 26.04 setup using the official Composer installer. You will also learn why each command matters, not just what to type. By the end, you will have a working Composer install and a clear idea of how to maintain it properly.
Prerequisites
- Ubuntu 26.04 or a compatible Ubuntu system.
- A user with sudo privileges.
- A working internet connection.
- PHP CLI installed, or the ability to install it.
- curl and unzip available for the install process.
- A terminal session on your local machine or server.
These tools matter because Composer runs through PHP and needs supporting utilities during setup. On a Linux server tutorial level workflow, this prevents most install failures before they happen.
Step 1: Update Your System
Refresh package lists
Run this first:
sudo apt update
This command refreshes Ubuntu’s package index. It tells your system which package versions are currently available, so you install the latest compatible files instead of stale ones.
Why this matters
A fresh package list reduces dependency errors. It also lowers the chance of pulling an older PHP package that conflicts with Composer or your project requirements.
Optional full upgrade
You can also upgrade installed packages:
sudo apt upgrade -y
This keeps the system current before you add new tools. On a server, that usually means fewer surprises later.
Step 2: Install Required Packages
Install PHP and utilities
Use this command:
sudo apt install -y php-cli php-mbstring php-xml php-zip curl unzip
This installs the core tools Composer needs. php-cli lets you run PHP from the terminal, curl downloads the installer, unzip handles archives, and the PHP extensions support common package features.
Why these packages matter
Composer does not work well on a half-ready PHP system. If php-zip or php-mbstring is missing, some projects will fail later even if the Composer install itself succeeds. Installing them now gives you a cleaner configure Composer on Ubuntu 26.04 workflow.
Expected result
After the install finishes, Ubuntu should return to the shell without errors. If a package is already installed, apt may simply skip it.
Step 3: Confirm PHP Works
Check the PHP version
Run:
php -v
You should see output similar to this:
PHP 8.x.x (cli) (built: ...)
Copyright ...
Zend Engine v4.x.x
Why this matters
Composer depends on PHP CLI, not just PHP in general. If php -v fails, Composer will fail too. Checking PHP first makes troubleshooting easier because you can separate PHP problems from Composer problems.
Step 4: Download the Composer Installer
Get the installer file
Run:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
This downloads the official installer script into your current directory. It is the standard way to fetch Composer before verification.
Why this matters
You should always verify the installer before running it. Downloading the script as a file lets you inspect and check it first, which is much safer than blindly executing a remote command.
Expected result
If the download works, the command returns no major output and creates composer-setup.php in your directory.
Step 5: Verify the Installer Hash
Check the SHA-384 signature
Run:
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;"
This compares the downloaded installer against Composer’s official SHA-384 hash. If the file matches, it is safe to continue.
Why this matters
This is the most important security step in the guide. It protects you from a modified or broken installer, and it shows a professional installation process instead of a quick shortcut. If the hash fails, delete the file and download it again.
Expected output
You should see:
Installer verified
If you see Installer corrupt, stop and repeat the download.
Step 6: Install Composer Globally
Run the installer
Use this command:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
This installs Composer in /usr/local/bin and names the command composer. That makes it available from anywhere in your terminal session.
Why this matters
A global install is the most practical choice for developers and sysadmins. You do not need to type the full path each time, and your shell can find Composer in the normal PATH search locations.
Expected output
A successful install usually ends with a message like this:
All settings correct for using Composer
Downloading...
Composer (version x.x.x) successfully installed to: /usr/local/bin/composer
Clean up the installer
Remove the setup file after installation:
rm composer-setup.php
This keeps the system tidy and avoids leaving an unused installer on disk.
Step 7: Verify Composer Works
Check the installed version
Run:
composer --version
You should see Composer’s version number and PHP runtime details. That confirms the binary is installed correctly and reachable from your shell.
Why this matters
This test proves three things at once. First, the install completed. Second, your PATH is correct. Third, the system can launch Composer with your installed PHP environment. That is exactly what you want from an Install Composer on Ubuntu 26.04 setup.
Step 8: Run Composer Diagnose
Check the environment
Run:
composer diagnose
Composer will scan for common problems such as missing extensions, network issues, or certificate problems. It is a fast way to catch issues before you start a real project.
Why this matters
Many Composer problems only show up after you try to install packages. composer diagnose gives you early warning, which saves time when you are setting up a dev machine or a server.
Expected result
A healthy system should report mostly OK messages. If something is wrong, Composer usually points to the missing piece.
Step 9: Use Composer in a Project
Initialize a project
Inside a project folder, run:
composer init
This starts a guided setup for creating composer.json. That file tells Composer what your project needs.
Add a package
For example:
composer require monolog/monolog
This installs a package and updates your dependency files.
Why this matters
Composer is only useful when it manages real project dependencies. This is where the tool starts saving time, improving consistency, and making deployments repeatable.
Troubleshooting
1. php: command not found
This usually means PHP CLI is missing. Install it with:
sudo apt install -y php-cli
Why it happens: Composer is a PHP program, so it needs the command-line interpreter before it can run.
2. Installer corrupt
This means the downloaded installer does not match the official hash. Delete it and download it again.
rm composer-setup.php
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Why it happens: the file may be incomplete, blocked, or changed during download.
3. composer: command not found
This usually means the binary was not installed in your PATH. Check the install directory:
ls -l /usr/local/bin/composer
Why it happens: the install may have failed, or the shell has not picked up the command path yet.
4. Missing PHP extensions
If Composer warns about zip, mbstring, or similar modules, install them:
sudo apt install -y php-zip php-mbstring php-xml
Why it happens: many PHP packages need these extensions to install or run correctly.
5. Network or certificate issues
If downloads fail, test your internet access and package sources. Then rerun:
composer diagnose
Why it happens: Composer must reach remote package repositories, so network and SSL problems can block installs.