How to Update Composer in Ubuntu

Composer is a dependency management tool for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. This makes it easy to keep your projects up-to-date and avoid conflicts between dependencies.

In this tutorial, we will show you how to update Composer to the latest version in Ubuntu. We will cover the steps on how to check the current version of Composer, how to uninstall the old version, and how to install the latest version.

First, remove the composer. Run the following command:

#! /bin/bash
sudo apt-get remove composer -y

Download the installer and composer setup:

#! /bin/bash
php -r "copy('', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/bin --filename=composer

Switching Composer Version

To change to version one, run the self-update command and pass in the --1 flag. This will change the composer to version one, and now you can install your dependencies.

#! /bin/bash
composer self-update --1

Once you have installed your dependencies, you can now run the same command and pass in --2 as the flag, which will switch back to composer version 2.

#! /bin/bash
composer self-update --2

Switching Composer Specific Version

You can also change to a specific version with the minor version number, like below.

#! /bin/bash
composer self-update 1.10.22
composer self-update 2.1.3

Revert Composer Version

To revert to the previous version, pass in the --rollback.

#! /bin/bash
composer self-update --rollback

Preview Composer Version

The command below will allow you to get the pre-released version for anyone interested in using the preview version.

#! /bin/bash
composer self-update --preview

With this guide you can now update the editor in your Ubuntu


How to Update Composer in Ubuntu
1.40 GEEK