Linux Notepad

Install and update 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.

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.

Install dependencies

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

If PHP is not installed, you can install it using the following command:

sudo apt update
sudo apt install php-cli php-zip -y

Install Composer

Note: For security precautions, the following commands should be run as a sudo user, not as root.

1. Download the Composer installer:

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

2. Run the installer to generate the composer.phar file:

php composer-setup.php && rm composer-setup.php

3. Install Composer globally:

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

4. Check the Composer version:

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.

Update Composer

As a non root user, copy composer file to the current directory:

cp /usr/local/bin/composer .

Run the following command to update the local composer file:

php composer self-update

Then move the updated composer file back to the global location:

sudo mv composer /usr/local/bin/composer

Check the Composer version again to confirm the update was successful:

composer --version

Resources

Back to homepage