How to install or upgrade to Composer v2
Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. It manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project.
Composer runs from the command line. It also allows users to install PHP applications that are available on Packagist which is its main repository containing available packages. It also provides autoload capabilities for libraries that specify autoload information to ease usage of third-party code.
Composer in its latest version, i.e., v2.2.7 requires PHP 7.2.5 to run. However we recommend you to use PHP 7.4 or higher. Composer is multi-platform and it should run equally well on Windows, Linux and macOS.
Composer offers a convenient installer that you can execute directly from the command line.
Download Composer from the official website using the following command:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Install latest version of Composer globally as a system wide executable:
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Note: you can choose a different version of composer to be installed providing --version parameter (e.g. --version=2.2.7).
This message should be shown after successful installation.
Remove the installer:
php -r "unlink('composer-setup.php');"
Upgrade old version
If you already have an older version of Composer you can upgrade it using integrated feature for that. Type the following command in your terminal:
composer self-update --2
To programmatically install specific major versions you can switch between --1 and --2 flags.
It will automatically download the latest stable version of the selected major flag.
To check the installation and start using the manager type composer in your command line. You will see an image as below and a list of available composer commands:
Note: image shows only a part of all available commands in Composer v2.