If you’re working with PHP on your Ubuntu 22.04 system, you might have the requirement to install Composer on your system. So in this article, you will learn how to install Composer on Ubuntu 22.04 system step-by-step. So let’s dive in.
What is Composer?
So before moving to the actual context of the article, let us give you a brief introduction to Composer. Composer is a famous dependency management tool for PHP which helps to make updates and dependencies installation easier. The composer is able to determine the required packages needed by your project which was developed in PHP language and starts to install it on your Ubuntu 22.04 system along with the right version based on the project’s need.
How To Install Composer on Ubuntu 22.04
As of now, we are quite aware of Composer, so let’s jump into the main topic of how to install Composer on your Ubuntu 22.04. The steps are as follows:
Step 1: Update your system
The First step you should follow is updating your apt packages in your Linux ubuntu system by running the following command
sudo apt update
Enter Y to continue and after that everything will be properly get installed.
Step 2: Download & install PHP Composer
Next, you have to download the PHP Composer installer script written in PHP using the “curl” command in your home directory.
cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
Now verify that the PHP Composer installer script matches the SHA-384 hash on the Composer Public Keys / Signatures page.
You can do that by using the following command.
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
After that execute the following PHP code for verifying the installation script.
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt';
unlink('composer-setup.php'); } echo PHP_EOL;
The installer verified proving the fact that the file you have is correct.
Step 3: Installing PHP Composer Command
Now that you have verified the installer, let’s install the PHP Composer on Ubuntu 22.04 by executing the following command
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
Hence we have installed PHP Composer.
Step 5: Verify PHP Composer installation
Lastly, you have to confirm whether the PHP Composer has been installed on Ubuntu 22.04 or not?Check using following command
composer
This confirms that Composer is successfully installed on your Ubuntu 22.04 system and available at the global level on your system.
Uninstall PHP Composer on Ubuntu 22.04
If you want to uninstall PHP Composer, use the following command in the terminal.
sudo rm /usr/local/bin/composer
Read More: How to Install Laravel on Ubuntu 22.04 [Super Easy Guide]
Conclusion
In this article, we discussed the installation and un-installation completely. I hope you have learned how to install composer on Ubuntu 22.04 which will help you to work with your PHP projects.