How to install Composer

By @whatisdrupal, 21 June, 2024
How to install Composer

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Command-line installation

To run the following script in your terminal.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
  • Download the installer to the current directory
  • Verify the installer SHA-384, which you can also cross-check here
  • Run the installer and then download the latest composer.phar in the current directory.
  • Remove the installer

Most likely, you want to put the composer.phar into a directory on your PATH, so you can simply call composer from any directory (Global install), using for example:

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

Source: https://getcomposer.org/download/