Composer 2 is a command-line tool utilized for managing dependencies for PHP. It makes it easy to install and organize PHP libraries and packages. More specifically, Composer permits PHP developers to declare the libraries and packages of their relevant projects and then automatically downloads and installs those dependencies into their projects. It is not a built-in tool on Ubuntu, but we can easily install and use it.
With the help of this tutorial, you will get to know the procedure of installing and uninstalling Composer 2 on Ubuntu 22.04.
How to Install Composer 2 on Ubuntu 22.04?
In this section, we have mentioned a step-by-step method of installing Composer 2 on Ubuntu 22.04.
Step 1: Launch Terminal
Go to the All-application menu and search for “Terminal” or you can simply hit “CTRL+ALT+T” to open it:
Step 2: Update System Packages
Now, make sure that your system packages are up-to-date:
sudo apt update
sudo apt upgrade
During the upgradation process, you will be asked to confirm it. To do so, hit “Y” and hit Enter:
Upgradation has been completed:
Step 3: Install Dependencies
Next, execute this command to install the required dependencies:
sudo apt install curl php-cli php-mbstring unzip
Hit “Y” to confirm installation:
Our required dependencies have been installed without any error:
Step 4: Download and Install Composer
The command below will get Composer 2 downloaded on your system:
curl -sS https://getcomposer.org/installer | php -- --version=2.0.13
Step 5: Move Composer Executable
Make Composer globally accessible by moving the executable to a directory that has been specified in your system’s path:
sudo mv composer.phar /usr/local/bin/composer
How to Verify/Check Composer Installation on Ubuntu 22.04?
Once Composer gets installed on your system, verify its version with below command:
Composer version 2.0.13 is installed on our Ubuntu 22.04.
How to Uninstall/Remove Composer 2 on Ubuntu 22.04?
Once you are done using Composer 2 on your system, you can uninstall it whenever you want. For the corresponding purpose, check out the provided instructions.
Step 1: Remove the Composer executable
If you have installed Composer globally by moving the executable to a directory, remove it using the mentioned command:
sudo rm /usr/local/bin/composer
Step 2: Remove Composer Configuration and Cache
Composer stores configuration and cache files in the user’s home directory. To remove them, use the following command:
rm -rf ~/.composer/
Step 3: Verify Uninstallation
Utilize the command below to verify if Composer 2 is still present on your system or not:
That was all from this effective tutorial about Composer 2 on Ubuntu 22.04.
To install Composer 2 on Ubuntu 22.04, upgrade the system packages first. Then, install the necessary dependencies using the “sudo apt install curl php-cli php-mbstring unzip” command. After that, execute the “curl -sS https://getcomposer.org/installer | php — –version=2.0.13” command for installing Composer 2. You can verify its installation through terminal. The Composer’s uninstallation method is also described in the tutorial.