Install Composer In Ubuntu

By : phpicoder Created : March 4, 2021

In this Tutorial, I will explain how to install composer in ubuntu opreting system, in this article we will mack step for how to install composer in ubuntu os, In this tutorial, you’ll install and get started with Composer on an Ubuntu system.

Composer is a dependency manager tracking local dependencies of your projects and libraries. get it here. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

Composer is not a package manager in the same sense as Yum or Apt are. Yes, it deals with "packages" or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project. By default it does not install anything globally.

What is Dependency management? :

Thus, it is a dependency manager. It does however support a "global" project for convenience via the global command.

Package is top repository. Now a days several most popular PHP frameworks are using composer as an internal part to manage dependencies such as laravel and symfony.

It is very easy and takes few steps to install Composer on your Ubuntu system.

*Installation in Ubuntu Or Linux:

Step 1: Update you package manager

First of al, Update you package manager using below command

sudo apt-get update

Step 2: Install PHP Packages

Now, let's install the dependencies. We'll need curl in order to download Composer and php-cli for installing and running it. The php-mbstring package is necessary to provide functions for a library we'll be using. git is used by Composer for downloading project dependencies, and unzip for extracting zipped packages. Everything can be installed with the following command:

sudo apt-get install curl php-cli php-mbstring git unzip

Step 3: Downloading Composer File

Downloading and Installing Composer

Composer provides an installer, written in PHP. Make sure you're in your home directory, and retrieve the installer using curl:

cd ~
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

You need to Download package for official site to go to following url - https://getcomposer.org/download/

Step 4: verify Composer Public Keys

run a short PHP script to verify that the installer matches the SHA-384 hash for the latest installer found on the Composer Public Keys / Signatures page. You will need to make sure that you substitute the latest hash for the highlighted value below:

php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Output
Installer verified

Step 5 Install Composer Locally:

This Step install composer locally, use the following Command:

php composer-setup.php

And Then check install composer locally, use the following Command:

php ./composer.phar
Output :
phpicoder@localhost:~# php ./composer.phar
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                /_/
Composer version 2.0.11 2017-01-27 18:23:41

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message

Step 6 Install Composer Globally:

This Step install composer globally, use the following Command:

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

This will download and install Composer as a system-wide command named composer, under /usr/local/bin. The output should look like this:

All settings correct for using Composer Downloading 2.0.11... Composer successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer

Step 6: Check Composer Install Or Not

To test Composer install or not, So run following commnad:

composer
Output :
phpicoder@localhost:~# composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                /_/
Composer version 2.0.11 2017-01-27 18:23:41

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message

Step 7: Delete composer-setup.php

Now Following command to delete composer-setup.php file

php -r "unlink('composer-setup.php');"

I hope it can help for you this tutorial....