How to Install Composer in ubuntu using command line

Posted by

To install a specific version of Composer, such as Composer 2.7.4, on Ubuntu via the command line, you’ll first need to ensure that Composer is either updated to or installed directly at that specific version. Here’s how you can do it:

Step 1: Check Existing Installation

First, check if you already have Composer installed and its current version:

composer --version

If the version is not 2.7.4 and you need to install or update to this version specifically, proceed with the following steps.

Step 2: Download Composer

If Composer is not installed or you need a specific version, you can download it directly from the Composer GitHub repository. Use wget or curl to download the specific 2.7.4 version:

wget https://getcomposer.org/download/2.7.4/composer.phar
# or
curl -o composer.phar https://getcomposer.org/download/2.7.4/composer.phar

Step 3: Make Composer Executable

After downloading, make the composer.phar file executable:

chmod +x composer.phar

Step 4: Move Composer to a Global Directory

Move the composer.phar file to a global directory such as /usr/local/bin to use Composer globally. Rename it to composer to use the composer command system-wide:

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

Step 5: Verify Installation

Ensure that the installation was successful and that the correct version of Composer is installed:

composer --version

This command should output Composer version 2.7.4 confirming that the correct version is installed.

Additional Considerations

If you encounter any permissions issues or if you are using Composer in a project-specific manner, you might also consider using a local installation method or managing versions via a tool like phpbrew or a containerized environment.

Using the above steps, you should be able to install or update to Composer version 2.7.4 on your Ubuntu system using the command line. If you need to manage multiple PHP versions or specific project requirements, consider additional tools that manage PHP environments alongside Composer.

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x