Linux Notepad

Install PHP composer on Debian

Composer is a dependency manager for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
Composer is not a package manager in the same sense as YUM or APT.
Instead, it is a dependency manager that works with libraries, projects, and dependencies.

These instructions are specifically for Debian-based Linux systems but should work on other Linux distributions with minimal modifications.

Before you install Composer, you need to have PHP installed on your system.
You can check if PHP is installed on your system by running the following command:

php -v

This setup was tested on Debian 12 (Bookworm), but it should work on other Debian-based systems, like Ubuntu.
The installation requires no additional dependencies besides PHP.

Single-line Command to Install Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" &&\
    php composer-setup.php &&\
    php -r "unlink('composer-setup.php');" &&\
    sudo mv composer.phar /usr/local/bin/composer &&\
    composer --version

The Composer command will be available globally after running the above command.

Step-by-Step Commands to Install Composer

Here's what each command does:

1. Download the Composer installer file

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

2. Generate the Composer PHAR file

php composer-setup.php

This runs the Composer installer to generate the composer.phar file.

3. Remove the installer file

php -r "unlink('composer-setup.php');"

4. Make Composer globally accessible

sudo mv composer.phar /usr/local/bin/composer

5. Verify the installation

composer --version

It should display something like this:

Composer version 2.8.4 2024-12-11 11:57:47
PHP version 8.2.26 (/usr/bin/php8.2)
Run the "diagnose" command to get more detailed diagnostics output.

Resources

Back to homepage