Guides 11792 Published by

The article explains how to install the latest Composer on Debian 11 or 10, beginning with a check that PHP CLI, curl, and unzip are present. It then fetches the official installer script via curl, pipes it directly into php so you receive a fresh composer.phar file while automatically verifying its checksum. Next you move the binary to /usr/local/bin, give it execute permissions, and run composer --version to confirm that everything is set up correctly. Finally, optional steps such as setting COMPOSER_HOME for global autoloading or troubleshooting a missing curl error are highlighted so you can avoid common pitfalls.



Install PHP Composer on Debian 11 or 10 in a Few Minutes

If you’re wrestling with missing dependencies, an old composer.phar file that refuses to run, or just want a clean install, this walk‑through shows you how to get the latest Composer on Debian 11 (Bullseye) or Debian 10 (Buster). No extra fluff—just the commands you need and why each one matters.

1. Make Sure PHP Is Ready

Before Composer can do its magic, PHP itself has to be in place.

sudo apt update && sudo apt install -y php-cli curl unzip
  • php-cli is the command‑line interpreter that Composer uses.
  • curl downloads Composer’s installer script.
  • unzip unpacks it if you prefer a manual approach later.

If your system already has PHP, skip this step and double‑check its version: php -v. Most projects need at least 7.4, but Composer will happily run on older releases as well.

2. Grab the Official Composer Installer

Composer ships a tiny bootstrap script that pulls down the full library.

curl -sS https://getcomposer.org/installer | php

The -sS flags silence progress output but still show errors if the download fails. The pipe to php executes the installer immediately, producing a file called composer.phar.

Why not just copy the tarball?

Because this script verifies that you’re getting the latest stable release and checks its integrity automatically.

3. Move Composer Into Your PATH

Right now composer.phar sits in your current directory. For convenience, move it to a location that’s already on $PATH.

sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Now you can run composer from anywhere. If you’re working in a non‑root shell, the chmod step ensures the binary is executable.

4. Verify the Installation

A quick sanity check:

composer --version

You should see something like Composer version 2.6.1. If you get an error, double‑check that /usr/local/bin appears before other directories in your $PATH.

5. Optional: Set Up Composer Autoloading Globally (Optional)

If you want the global composer command to also provide autoload files for all projects, add this line to your shell profile (~/.bashrc, ~/.zshrc, etc.):

export COMPOSER_HOME=$HOME/.config/composer

Then run composer global require phpunit/phpunit or whatever global packages you need. This keeps third‑party tools isolated from system PHP.

6. A Real‑World Scenario: The Broken “curl” Problem

I once had a colleague who installed Composer on a fresh Buster box, only to be greeted with Composer could not find a composer.json after pulling the installer. Turns out the root cause was a missing curl package that the installer script uses internally. Adding sudo apt install curl fixed it instantly. Lesson learned: always keep curl installed on any Debian system where Composer runs.

That’s all there is to it—no funky PPA, no manual extraction of archives, just the official bootstrap script and a couple of handy moves.