Composer is a command-line program, so you install it once on your computer.
Check that PHP works first
Composer needs PHP on your command line.
php -v
If this prints a version number starting with PHP 8, you are ready. If not, see Installing PHP.
Windows
The easiest way is the Composer-Setup.exe installer from getcomposer.org. It finds your PHP, adds Composer to your PATH and installs it. Open a new terminal window afterwards.
macOS
With Homebrew:
brew install composer
Linux
Many distributions have a package (sudo apt install composer), but it can be an older version. The official instructions on getcomposer.org/download install the latest version with a short script that checks a signature. Follow those, because the exact hash changes with each release.
Afterwards, move the file to a folder on your PATH:
sudo mv composer.phar /usr/local/bin/composer
Check the installation
composer --version
You should see something like Composer version 2.x.x.
A local composer.phar
You can also keep a composer.phar file inside a project and run it with php composer.phar. This is useful on servers where you cannot install programs system-wide. Everything in this chapter works the same way, with php composer.phar in place of composer.
Update Composer itself
composer self-update
Docker
If you use Docker, the official composer image has it ready:
docker run --rm -v "$PWD":/app composer require league/commonmark
Common problems
| Problem | Likely reason |
|---|---|
composer: command not found | Composer is not on your PATH. Open a new terminal, or fix PATH |
Your PHP version (...) does not satisfy requirement | The package needs a newer PHP than the one Composer uses |
| SSL or “could not resolve host” errors | Network, proxy or certificate issue. Check your internet connection |
| Out of memory | Run COMPOSER_MEMORY_LIMIT=-1 composer update once |
A needed extension is missing (ext-mbstring, ext-curl) | Enable it in php.ini |
Which PHP does Composer use?
Composer uses the PHP found on your PATH. If you have several versions installed (for example through XAMPP or Laragon), check which one you get with php -v, and make sure it is the one you want.
Do not run Composer as root
sudo composer install can leave files owned by root and can run package scripts with full permissions. Run Composer as your normal user.