# How to install Composer on Ubuntu 22.04?

{% embed url="<https://youtu.be/mVvYHTEvTh4>" %}

### Overview <a href="#howtoinstallcomposeronubuntu22.04-overview" id="howtoinstallcomposeronubuntu22.04-overview"></a>

Composer is a tool frequently used for managing dependencies in PHP. Its main purpose is to simplify the installation and updating process of project dependencies. Composer identifies the packages that a project relies on and installs them, utilizing the versions that are compatible with the project's specifications. It is also a popular choice for creating new projects based on well-known PHP frameworks.

### Prerequisites <a href="#howtoinstallcomposeronubuntu22.04-prerequisites" id="howtoinstallcomposeronubuntu22.04-prerequisites"></a>

There are certain prerequisites that need to be met before you begin.&#x20;

* Ubuntu 22.04 LTS configured on your system.
* Non-root sudo user privileges.

### Get Started <a href="#howtoinstallcomposeronubuntu22.04-getstarted" id="howtoinstallcomposeronubuntu22.04-getstarted"></a>

**Step 1: Configuring PHP and other dependencies**

* Update the package index:

```
sudo apt update
```

* Proceed with installing the necessary prerequisites, such as php-cli:

```
sudo apt install php-cli unzip
```

**Step 2: Installing Composer**

* Ensure that you are in the home directory and then use curl to obtain the Composer installer:

```
cd ~
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
```

* &#x20;Use the 'curl' command to retrieve the latest signature and save it in a shell variable:

```
HASH=`curl -sS https://composer.github.io/installer.sig`
```

* Confirm the acquired value by executing the following command:

```
echo $HASH
```

![](http://customer.acecloudhosting.com/index.php?rp=/images/kb/1081_comp3.png)

{% hint style="info" %}
Visit the [Composer Public Keys / Signatures page](https://composer.github.io/pubkeys.html) and confirm that the installer matches to the SHA-384 hash of the most recent installer.&#x20;
{% endhint %}

* Ensure that the installation script is secure by running the PHP code provided on the [Composer ](https://getcomposer.org/download/)[download page.](https://getcomposer.org/download/)

{% hint style="info" %}
**Note:** To proceed, you must ensure that the installation script is not corrupted and that you have used the correct hash. If you encounter an 'Installer corrupt' error message, re-download the installation script and verify it again. Only after obtaining an 'Installer Verified' message should you proceed further.
{% endhint %}

```
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;"
```

![](http://customer.acecloudhosting.com/index.php?rp=/images/kb/1082_2023-03-21-16_11_42-Clipboard.png)

* To set up Composer globally, execute the command below. This will fetch and install Composer as a command that can be accessed from anywhere in the system, and it will be called "composer", located in the /usr/local/bin directory.

```
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
```

![](http://customer.acecloudhosting.com/index.php?rp=/images/kb/1083_comp2.png)

* Verify your installation:

```
composer
```

<figure><img src="http://customer.acecloudhosting.com/index.php?rp=/images/kb/1080_composer-1.png" alt=""><figcaption></figcaption></figure>

### Conclusion <a href="#howtoinstallcomposeronubuntu22.04-conclusion" id="howtoinstallcomposeronubuntu22.04-conclusion"></a>

This confirms that Composer has been installed on your system successfully and is accessible throughout the system.
