How to Install Composer on AlmaLinux 9

Composer is 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@server ~]# dnf install php
Last metadata expiration check: 1:49:53 ago on Fri May 27 18:17:07 2022.
Dependencies resolved.
==============================================================================================================
 Package                         Architecture     Version                           Repository           Size
==============================================================================================================
Installing:
 php                             x86_64           8.0.13-1.el9                      appstream            13 k
Installing dependencies:
 almalinux-logos-httpd           noarch           90.5-1.el9                        appstream            18 k
 apr                             x86_64           1.7.0-11.el9                      appstream           123 k
 apr-util                        x86_64           1.6.1-20.el9                      appstream            95 k
 apr-util-bdb                    x86_64           1.6.1-20.el9                      appstream            13 k
 httpd-filesystem                noarch           2.4.51-7.el9_0                    appstream            14 k
 httpd-tools                     x86_64           2.4.51-7.el9_0                    appstream            81 k
 libxslt                         x86_64           1.1.34-9.el9                      appstream           240 k
 mailcap                         noarch           2.1.49-5.el9                      baseos               32 k
 nginx-filesystem                noarch           1:1.20.1-10.el9.alma              appstream            11 k
 oniguruma                       x86_64           6.9.6-1.el9.5                     appstream           217 k
 php-common                      x86_64           8.0.13-1.el9                      appstream           666 k

Download Composer installer

dnf -y install wget

Output:

[root@server ~]# dnf -y install wget
Last metadata expiration check: 1:50:55 ago on Fri May 27 18:17:07 2022.
Dependencies resolved.
==============================================================================================================
 Package               Architecture            Version                       Repository                  Size
==============================================================================================================
Installing:
 wget                  x86_64                  1.21.1-7.el9                  appstream                  772 k

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

To install Composer locally by running the following command

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

Output:

[root@server ~]# wget https://getcomposer.org/installer -O composer-installer.php
--2022-05-27 20:08:59--  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: 58140 (57K) [application/octet-stream]
Saving to: ‘composer-installer.php’

composer-installer.php      100%[=========================================>]  56.78K  --.-KB/s    in 0.009s

2022-05-27 20:08:59 (6.50 MB/s) - ‘composer-installer.php’ saved [58140/58140]

Installing PHP Composer

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

Output:

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

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

Verify the PHP Composer version once the installation is done

composer --version

Output:

[root@server ~]# composer --version
Composer version 2.3.5 2022-04-13 16:43:00

Testing Composer

To test your installation, run the following command.

composer

Output:

[root@server ~]# composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.3.5 2022-04-13 16:43:00

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display help for the given command.

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