How to Install PHP Composer on Ubuntu 21.10

Composer is basically a dependency manager for the programming language, PHP. It functions as some sort of project manager that helps the programmer manage dependencies that will be used on a project-to-project basis.

Install Dependencies

  apt update

apt install wget php-cli php-zip unzip


root@server:~# apt install wget php-cli php-zip unzip
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
wget is already the newest version (1.21-1ubuntu3).
wget set to manually installed.
php-zip is already the newest version (2:8.0+82~0build1).
php-zip set to manually installed.
Suggested packages:
The following NEW packages will be installed:
  php-cli unzip

Download and Install Composer

Make sure you’re in your home directory and download the Composer installer using wget.

  cd ~

  wget -O composer-setup.php


root@server:~# wget -O composer-setup.php
--2021-09-12 15:06:34--
Resolving (, 2001:41d0:302:1100::8:104f
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58460 (57K) [application/octet-stream]
Saving to: ‘composer-setup.php’

Now, download and install Composer, under /usr/local/bin by running the following command.

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


root@server:~# php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer

Composer (version 2.1.6) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

To test your installation, run the following command.



root@server:~# composer
Do not run Composer as root/super user! See for details
Continue as root/super user [yes]? yes
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer version 2.1.6 2021-08-19 17:11:08

  command [options] [arguments]

  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
      --no-cache                 Prevent use of the cache
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug