How to Install Composer on Debian 12, 11 or 10 Linux

Composer is a dependency manager for PHP that simplifies the process of managing libraries and packages required for your projects. It ensures that you have the correct versions of the libraries, helps manage updates, and maintains a consistent environment across your development and production systems. Composer allows you to specify the libraries your project depends on and installs them for you, making it an essential tool for modern PHP development.

To install Composer on Debian 12, 11, or 10, you can follow a straightforward command-line process. This guide will walk you through the steps to set up Composer, ensuring you can efficiently manage your PHP project dependencies.

Update Debian Before Composer Installation

Before we begin, we must ensure that our package list is up-to-date. To do this, open up a terminal and run the following command.

sudo apt update

The below command can update any packages that are no longer current on your system.

sudo apt upgrade

Install PHP

To use PHP Composer, we must first have PHP installed on our system. To install PHP on Debian, run the following command.

sudo apt install php

The command given will install the standard Debian repository version of PHP.

Note: If you want to install a different version of PHP or the latest stable release, check out my guide on installing the latest version of PHP on Debian.

Install Composer

Installing PHP Composer globally on Linux is a great way to make the tool available to all users on your system. Here are the steps to install PHP Composer globally on Linux.

Open a terminal and run the following command to download the Composer installer:

curl -sS https://getcomposer.org/installer -o composer-setup.php

If the curl command fails, you may need to install the package.

sudo apt install curl -y

Run the following command for users who desire the global installation of Composer.

sudo php composer-setup.php --install-dir=bin --filename=composer

Once Composer is installed globally, all users on the system can use it.

Alternatively, if you want to install Composer in a specific directory, you can specify the directory using the –filename= option, for example.

sudo php composer-setup.php --install-dir=/usr/local/composer --filename=phpcomposer

You can also add the directory to your PATH by editing the .bashrc or .bash_profile file, for example:

echo 'export PATH="$PATH:/usr/local/composer"' >> ~/.bashrc

This way, you can use the Composer command from any directory.

Verify Composer Installation

Run the following command to verify that PHP Composer has been installed correctly:

composer

You should see the version of the Composer along with the usage instructions.

Getting Started with Composer

Once PHP Composer is installed, you can use it to manage the dependencies of your PHP projects. For example, you can run the following command to create a new project with PHP Composer.

composer create-project --prefer-dist laravel/laravel myproject

This command will create a new Laravel project in a directory called “myproject.” You can also use the composer command to install and update dependencies in an existing project. For example, you can run the following command to add a new package to your project.

composer require <package-name>

To update a current package, you can run the following command.

composer update <package-name>

Conclusion

With Composer successfully installed on your Debian system, you can streamline the management of your PHP project dependencies. Ensure you regularly update Composer to benefit from the latest features and improvements. Utilize Composer’s powerful capabilities to maintain consistency and efficiency in your development workflow. Enjoy the convenience and reliability that Composer brings to your PHP projects.

Leave a Comment