Install Composer

  • Last updated Apr 25, 2024

In this tutorial, we will show you how to install Composer on Windows, Ubuntu, Linux, and macOs.

Composer is a dependency management tool in PHP that allows you to manage libraries your projects are dependent on by installing and updating them for you.

Composer is not a package manager such as Yum or Apt. However, it manages packages or libraries on a per-project basis by installing any dependencies in a directory (example vendor) inside your project. By default, Composer does not install any dependencies globally but for convenience it supports a global project via the global command.

Installing Composer on Windows

Download Composer.exe and run. It will install the latest version of Composer. After installation, you should setup your PATH so that you can call the composer command from any directory via the command line.

Installing Composer on Ubuntu / Linux / macOs

To install Composer to the current directory, 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') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

The above script will download the installer to the current directory, verify the installer SHA-384, run the installer and remove the installer.

The above script will also download the latest composer.phar in your current directory. You can move the composer.phar in a directory that is part of your PATH so that to make it accessible globally.

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

Check which composer version is installed on your computer using the command below:

composer --version

To see the installation process in detail, go to the official site of Composer .