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
Output:
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:
zip
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 https://getcomposer.org/installer
Output:
root@server:~# wget -O composer-setup.php https://getcomposer.org/installer
--2021-09-12 15:06:34-- https://getcomposer.org/installer
Resolving getcomposer.org (getcomposer.org)... 54.36.53.46, 2001:41d0:302:1100::8:104f
Connecting to getcomposer.org (getcomposer.org)|54.36.53.46|: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
Output
root@server:~# php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer
Downloading...
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.
composer
Output:
root@server:~# composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.1.6 2021-08-19 17:11:08
Usage:
command [options] [arguments]
Options:
-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
Done.