How to Install Composer on AlmaLinux 8

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.

Installing PHP

dnf install @php

Output:

[root@vps ~]# dnf install @php
Last metadata expiration check: 0:05:17 ago on Tue 23 Feb 2021 12:52:38 PM EST.
Dependencies resolved.
================================================================================
 Package          Arch   Version                                Repo       Size
================================================================================
Installing group/module packages:
 php-cli          x86_64 7.2.24-1.module_el8.3.0+2010+7c76a223  appstream 3.1 M
 php-common       x86_64 7.2.24-1.module_el8.3.0+2010+7c76a223  appstream 659 k
 php-fpm          x86_64 7.2.24-1.module_el8.3.0+2010+7c76a223  appstream 1.6 M
 php-json         x86_64 7.2.24-1.module_el8.3.0+2010+7c76a223  appstream  72 k
 php-mbstring     x86_64 7.2.24-1.module_el8.3.0+2010+7c76a223  appstream 579 k
 php-xml          x86_64 7.2.24-1.module_el8.3.0+2010+7c76a223  appstream 187 k

Download Composer installer

dnf -y install wget

Output:

[root@vps ~]# dnf -y install wget
Last metadata expiration check: 0:06:16 ago on Tue 23 Feb 2021 12:52:38 PM EST.
Dependencies resolved.
================================================================================
 Package       Architecture    Version                 Repository          Size
================================================================================
Installing:
 wget          x86_64          1.19.5-10.el8           appstream          733 k

Transaction Summary
================================================================================
Install  1 Package

To install Composer locally by running following command

wget https://getcomposer.org/installer -O composer-installer.php

Output:

[root@vps ~]# wget https://getcomposer.org/installer -O composer-installer.php
--2021-02-23 12:59:23--  https://getcomposer.org/installer
Resolving getcomposer.org (getcomposer.org)... 142.44.245.229, 2607:5300:201:2100::4:d105
Connecting to getcomposer.org (getcomposer.org)|142.44.245.229|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58460 (57K) [application/octet-stream]
Saving to: ‘composer-installer.php’

composer-installer. 100%[===================>]  57.09K  --.-KB/s    in 0.1s

2021-02-23 12:59:24 (420 KB/s) - ‘composer-installer.php’ saved [58460/58460]

Installing PHP Composer

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

Output:

[root@vps ~]# php composer-installer.php --filename=composer --install-dir=/usr/local/bin
All settings correct for using Composer
Downloading...

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

Verify the PHP Composer version once installation is done

composer --version

Output:

[root@vps ~]# composer --version
Composer version 2.0.10 2021-02-23 16:11:37

Testing Composer

To test your installation, run the following command.

composer

Output:

[root@vps ~]# composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.0.10 2021-02-23 16:11:37

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message

CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS