# How to install Composer on Ubuntu 22.04

In [Ubuntu](https://www.ionos.com/digitalguide/server/know-how/ubuntu-the-linux-system-for-everyone/ "Ubuntu: The Linux system for everyone") 22.04, you can install the [PHP](https://www.ionos.com/digitalguide/websites/website-creation/learn-php-our-all-encompassing-php-tutorial-for-beginners/ "Learn PHP: Our all-encompassing PHP tutorial for beginners") package manager Composer in just a few steps. With the command-line tool curl, installation is quick and simple.

## Ubuntu 22.04: Install Composer step by step

To install Composer, you first need to ensure that PHP is already installed on your system and you have access to PHP via the terminal. You can check both by entering the following command in the terminal:

```bash
php
```

If there’s an error message, you can install the command line tool for [PHP 8](https://www.ionos.com/digitalguide/websites/web-development/php-8/ "PHP 8") with the following command:

```bash
sudo apt install php8.1.cli
```

[![Image: Terminal after running the command “php”](https://www.ionos.com/digitalguide/fileadmin/_processed_/e/3/csm_composer-command-php_2726b25154.webp "Terminal after running the command “php”")](https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/composer-command-php.png) If you haven’t installed the PHP command line tool, Ubuntu will suggest the appropriate commands in the terminal. Once you’ve verified that you can use PHP on your system, you can begin installing PHP Composer.

Tip You can [use Composer in IONOS web hosting packages](https://www.ionos.com/digitalguide/websites/web-development/using-php-composer-in-ionos-webhosting-packages/ "Using PHP Composer in IONOS web hosting packages"). In addition to PHP support, [web hosting](https://www.ionos.com/hosting/web-hosting "Web hosting plans from IONOS") plans from IONOS offer many other benefits such as built-in DDoS protection.

### Step 1: Update the system

First, you’ll want to make sure your [Linux](https://www.ionos.com/digitalguide/server/know-how/linux-the-cost-effective-alternative-to-windows/ "Linux – the cost-effective alternative to Windows") system is in good shape by running available updates. You may need to confirm execution of the upgrades by choosing `y` (yes). You can use the following terminal commands for this:

```bash
sudo apt update
sudo apt upgrade
```

Updating your system may take a few moments. How long it takes will depend on how many updates you need to install.

### Step 2: Install required packages

For the Ubuntu installation of Composer to work, you need to install a few packages that Composer requires for installation. This includes, for example, the command line tool curl or the version control Git.

The packages can also be downloaded directly in the terminal using the following commands:

```bash
sudo apt install curl php-mbstring git unzip
```

### Step 3: Install Composer

Now you can get started with the actual installation of PHP Composer on Ubuntu 22.04. You do this by using the downloaded curl tool and typing the following command into terminal:

```bash
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
```

[![Image: Terminal after running the installation command for Composer](https://www.ionos.com/digitalguide/fileadmin/_processed_/1/2/csm_composer-successfully-installed_a2d810aeb8.webp "Terminal after running the installation command for Composer")](https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/composer-successfully-installed.png) Terminal verifies the success of the Ubuntu installation of Composer. ### Step 4: Check if installation was successful

As a final step, manually check if the Composer installation was successful by accessing the package manager. If this doesn’t work, your $PATH environment variable may not be configured correctly. The command below invokes the current version of Composer:

```bash
Composer
```

If the installation of Composer on Ubuntu 22.04 went smoothly, terminal will show the following:

[![Image: Terminal after running the command “composer”](https://www.ionos.com/digitalguide/fileadmin/_processed_/7/4/csm_composer-version_eaab04ab5e.webp "Terminal after running the command “composer”")](https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Screenshots_2023/composer-version.png) The Composer font and current Composer version are displayed upon launching Composer.  Note If you’re using an operating system other than Ubuntu 22.04, you can still use Composer. Just take a look at our other installation guides:

- [Composer installation on Ubuntu 20.04](https://www.ionos.com/digitalguide/server/configuration/php-composer-installation-on-ubuntu-2004/)
- [Composer installation on Windows 10](https://www.ionos.com/digitalguide/server/configuration/php-composer-installation-on-windows-10/)
- [Composer installation on Windows 11](https://www.ionos.com/digitalguide/server/configuration/php-composer-installation-on-windows-11/)

## First steps when using Composer

The package manager is used in PHP projects to manage and update dependencies. To help you get started with Composer and avoid common errors, we’ve compiled the most important Composer commands.

### Step 1: Create *composer.json* file

The main task of Composer is to manage the dependencies of your PHP project. The central place to specify these dependencies is the *composer.json* file. This can be created manually. Alternatively, you can specify to have the JSON file be set up automatically when you create your first dependency. The Composer command to manually create a *composer.json* file is as follows:

```bash
composer init
```

### Step 2: Add dependencies to your project

You can also use a Composer command to insert a dependency into your project. This ensures that the *composer.json* file is updated to the appropriate state. In the example code, the popular logging library Monolog is inserted as a dependency in a PHP project.

```bash
composer require monolog/monolog
```

### Step 3: Update dependencies

Every now and then it’s necessary to update the dependencies of a PHP project. A Composer command can be used for this. It updates all dependencies you’ve added to your project in a single step:

```bash
composer update
```


This is a markdown version of: [https://www.ionos.com/digitalguide/server/configuration/how-to-install-composer-on-ubuntu-2204/](https://www.ionos.com/digitalguide/server/configuration/how-to-install-composer-on-ubuntu-2204/) for AI/LLM consumption.