How To Install Composer In Ubuntu

By : PHPErrorCode July 17, 2017 716 Views php,laravel,ubuntu

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:—

First of al, Update you package manager using below command

sudo apt-get update

Step 2:

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 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 ~
curl -sS -o composer-setup.php

Step 4:

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') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Installer verified

Step 5:

To check install composer globally, use the following:

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 1.1.1... Composer successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer

Step 6:

To test your installation, run:

Note: Update all dependencies of project —> goto Your project directory and use the following
composer update

Go to project path throughcd [project path] and run composer update command it will update all the libraries added in composer.json file in require key. require simply tell to composer which dependencies project required.

If you are developing project using PHP framework and not using composer then use it and leave worrying about package management.