How to Install Composer on CentOS 8

Install Composer on CentOS 8

In this article, we will have explained the necessary steps to install and configure Composer on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Composer is one the best dependency management tool for PHP which can install and update project dependency seamlessly. When installing a package it also checks on which another package current package depends on and then it installs all the dependencies.

Install Composer on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo dnf install epel-release
sudo dnf update

Step 2. Install Dependencies packages.

Now, we need to install php related packages using dnf:

sudo dnf install php php-cli php-zip php-json

Step 2. Install Composer on CentOS 8.

We can download the Composer installer with php:

cd ~
curl -sS -o composer-setup.php

You can verify that the installer matches the SHA-384 hash for the data integrity of latest installer found on the Composer Public Keys:

HASH="$(wget -q -O -"

Check if installation script is corrupted using command:

php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"


Installer Verified

Then, run following command to install Composer globally inside /usr/local/bin directory:

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

Run the following command to confirm the installation:

$ composer
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer 1.6.3 2019-12-05 16:46:32

  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.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

To learn more about Composer and find out how to get started with using this package manager, our recommendation is to read the official documentation at

Congratulation, you have learned how to install and configure Composer on CentOS 8. If you have any question, please leave a comment below.