How to Install Composer in Ubuntu (16.04 & 18.04)

How to Install Composer in Ubuntu (16.04 & 18.04). In this tutorial series, We will discuss about how to install composer in ubuntu system step by step. A complete guide on install composer in ubuntu and discuss about how to check composer installed in your system, open command prompt and type the command “composer”.  If you want to check composer version to run the command on command prompt “Composer –version” .

And Also discuss, How to update composer in ubuntu system.

Introduction Composer

Composer  is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

PHP composer is frequently used to factlitate the installation and update of dynamic PHP applications that needs easier management… using composer dependancies tool, these packages can easily be installed and managed… It maintains a list of required packages in a JSON file called composer.json.

Prerequisites

  • Before we install composer in ubuntu, you should ensure that all the required dependencies are properly installed on your Ubuntu 14.04 / 16.04 / 18.10 server.
  • Operating Systems: Ubuntu Linux 14.04 / 16.04 / 18.10 LTS.
  • PHP must be installed and configured, version 5.3 or higher.

1. Installing the Dependencies

Before you download and install Composer in Ubuntu, you’ll want to make sure your server has all dependencies installed.

First, update the package manager cache by running :

 sudo apt-get update 

2. Install Composer in Ubuntu

To install composer in Ubuntu system. We just need to download composer executable and put under bin directory.

 cd ~ 
curl -sS https://getcomposer.org/installer -o composer-setup.php

3. Verify the Installer, whether it is matching the SHA-384 hash.

Now run the following command to verify the Composer installer.

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

Output

Installer verified

Note: If you see Installer corrupt, then you’ll need to re-download the installation script again and double check that you’re using the correct hash.

4. Composer install globally in ubuntu system

Next, to install composer globally, use the following command which will download and install Composer as a system-wide command named composer, under /usr/local/bin :

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

The above command will download and install the composer in ubuntu system as system-wide command composer at /usr/local/bin.

The Output will look like the following.

All settings correct for using Composer
Downloading 1.1.1...

Composer successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

5. To test your composer installation, run:

composer

And you’ll see this output displaying Composer version

______
/ ____/___  ____ ___  ____  ____  ________  _____
/ /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.7.2 2018-12-16 16:57:12

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.

6. Upgrade Composer on Ubuntu

You can download the latest version of the composer by executing same commands used for installation. The composer also has capabilities to update itself. Use the following command to update composer itself.

sudo composer self-update

That’s it! You have successfully installed Composer on your Ubuntu System

If you have any questions or thoughts to share, use the comment form below to reach us.

Spread the love

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *