How to install or upgrade to Composer v2

  • avatar
  • 36.5K Views
  • 15 Likes
  • 4 mins read

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.

Prerequisites

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.

Installation

Composer offers a convenient installer that you can execute directly from the command line.

  1. Download Composer from the official website using the following command:

    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  2. 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).

    composer2_installed.png
    This message should be shown after successful installation.

  3. 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.

composer2_upgrade.png

It will automatically download the latest stable version of the selected major flag.

Using Composer

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:

composer2_commands.png
Note: image shows only a part of all available commands in Composer v2.

 Join Our Monthly Newsletter

Get the latest news and popular articles to your inbox every month

We never send SPAM nor unsolicited emails

0 Comments

Leave a Reply

Your email address will not be published.

Replying to the message: View original

Hey visitor! Unlock access to featured articles, remove ads and much more - it's free.