How to Install and Use PHP Composer on Ubuntu 18.04/20.04

How to Install and Use PHP Composer on Ubuntu 18.04/20.04

How to Install Composer in Ubuntu; Through this tutorial, we will learn how to install composer in ubuntu system step by step. A complete guide on installing composer in ubuntu and discuss how to check composer installed in your system, open command prompt and type the command “composer”.  If you want to check the composer version to run the command on the command prompt “Composer –version” .

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

Introduction Composer

A 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 facilitate the installation and update of dynamic PHP applications that need easier management… using the composer dependencies 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.

How to install Composer in Ubuntu

Use the following steps to install or upgrade composer in ubuntu machine; as follows:

  • 1. Installing the Dependencies
  • 2. Install Composer in Ubuntu
  • 3. Verify the Installer, whether it is matching the SHA-384 hash.
  • 4. Composer install globally in ubuntu system
  • 5. To test your composer installation, run:
  • 6. Upgrade Composer on Ubuntu

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 the composer executable and put it under the 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 the ubuntu system as a 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 the same commands used for installation. The composer also has the capabilities to update itself. Use the following command to update the 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.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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