How To Install Composer on Ubuntu 22.04 LTS Easily

0

If you’re someone who is working with PHP on your Ubuntu 22.04 system, you might have the requirement to install it on your Ubuntu 22.04 system. So in this article, you will learn how to install Composer on your Ubuntu 22.04 system step-by-step. So follow these steps so that you can smoothly install Composer on Ubuntu 22.04 system without any problem.

What is Composer?

So before moving to the actual content, 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
Install Composer on Ubuntu 22

Enter Y to continue and after that everything will be properly get installed.

Step 3: 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;
Install Composer on Ubuntu 22

The installer verified proving the fact that the file you have is correct.

Step 4: Installing PHP Composer

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
Install Composer on Ubuntu 22

Hence we have installed PHP Composer.

Step 5: Verify PHP Composer installation

Lastly, you have to confirm whether the PHP Composer has been installed or not using the following command

Install Composer on Ubuntu 22

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

Conclusion

In this article we discussed the installation and uninstallation of PHP Composer on Ubuntu 22.04  which will help you to work with your PHP projects.

LEAVE A REPLY

Please enter your comment!
Please enter your name here