How to install composer in Ubuntu 16.04

To install Composer in Ubuntu 16.04

Composer is a dependency manager tool for PHP. The basic function of Composer is to install and update the libraries for your project. Composer can be used with each individual project like Mediawiki or even your own custom app written in PHP. There are many open source projects and frameworks written in php use Composer to manage and install their packages and dependencies. In this tutorial you will learn how to install composer globally on Debian or Ubuntu Linux server.

Installing Composer

The installation of Composer requires the prior installation of PHP. Use the following command for the same purpose.

root@linuxhelpubnt:~# apt-get install php
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libpango1.0-0 libpangox-1.0-0
Use ' sudo apt autoremove'  to remove them.
The following additional packages will be installed:
  php-common php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-json php7.0-opcache
  php7.0-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  php php-common php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-json php7.0-opcache
  php7.0-readline
0 upgraded, 9 newly installed, 0 to remove and 15 not upgraded.
Need to get 3,526 kB of archives.
After this operation, 14.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 php-common all 1:35ubuntu6 [10.8 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-common amd64 7.0.13-0ubuntu0.16.04.1 [833 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-json amd64 7.0.13-0ubuntu0.16.04.1 [16.9 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-opcache amd64 7.0.13-0ubuntu0.16.04.1 [76.1 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-readline amd64 7.0.13-0ubuntu0.16.04.1 [12.9 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-cli amd64 7.0.13-0ubuntu0.16.04.1 [1,282 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 php7.0-fpm amd64 7.0.13-0ubuntu0.16.04.1 [1,289 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0 all 7.0.13-0ubuntu0.16.04.1 [1,292 B]
Get:9 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 php all 1:7.0+35ubuntu6 [2,832 B]
Fetched 3,526 kB in 26s (132 kB/s)                                                          
Selecting previously unselected package php-common.
(Reading database ... 172903 files and directories currently installed.)
Preparing to unpack .../php-common_1%3a35ubuntu6_all.deb ...
Unpacking php-common (1:35ubuntu6) ...
Selecting previously unselected package php7.0-common.
Preparing to unpack .../php7.0-common_7.0.13-0ubuntu0.16.04.1_amd64.deb ...
Unpacking php7.0-common (7.0.13-0ubuntu0.16.04.1) ...
Selecting previously unselected package php7.0-json.
Preparing to unpack .../php7.0-json_7.0.13-0ubuntu0.16.04.1_amd64.deb ...
Unpacking php7.0-json (7.0.13-0ubuntu0.16.04.1) ...
Selecting previously unselected package php7.0-opcache.
Preparing to unpack .../php7.0-opcache_7.0.13-0ubuntu0.16.04.1_amd64.deb ...
Unpacking php7.0-opcache (7.0.13-0ubuntu0.16.04.1) ...
Selecting previously unselected package php7.0-readline.
Preparing to unpack .../php7.0-readline_7.0.13-0ubuntu0.16.04.1_amd64.deb ...
Unpacking php7.0-readline (7.0.13-0ubuntu0.16.04.1) ...
Selecting previously unselected package php7.0-cli.
Preparing to unpack .../php7.0-cli_7.0.13-0ubuntu0.16.04.1_amd64.deb ...
Unpacking php7.0-cli (7.0.13-0ubuntu0.16.04.1) ...
Selecting previously unselected package php7.0-fpm.
Preparing to unpack .../php7.0-fpm_7.0.13-0ubuntu0.16.04.1_amd64.deb ...
Unpacking php7.0-fpm (7.0.13-0ubuntu0.16.04.1) ...
Selecting previously unselected package php7.0.
Preparing to unpack .../php7.0_7.0.13-0ubuntu0.16.04.1_all.deb ...
.
.
.
Creating config file /etc/php/7.0/fpm/php.ini with new version
Setting up php7.0 (7.0.13-0ubuntu0.16.04.1) ...
Setting up php (1:7.0+35ubuntu6) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...


Once it is done, download the composer.phar file. Use the following command for the same purpose.

root@linuxhelpubnt:~# wget https://getcomposer.org/composer.phar
--2017-02-15 19:50:23--  https://getcomposer.org/composer.phar
Resolving getcomposer.org (getcomposer.org)... 87.98.253.108, 2001:41d0:a:7b19::2
Connecting to getcomposer.org (getcomposer.org)|87.98.253.108|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1827006 (1.7M) [application/octet-stream]
Saving to: ‘ composer.phar’ 

composer.phar           100%[============================> ]   1.74M   129KB/s    in 9.7s    

2017-02-15 19:50:34 (183 KB/s) - ‘ composer.phar’  saved [1827006/1827006]  

And rename that composer.phar file to composer .

root@linuxhelpubnt:~# mv composer.phar composer

Next run the composer file for checking the composer.

root@linuxhelpubnt:~# ./composer



Next move the composer file to “ /usr/local/bin/” for run composer command from any location.

root@linuxhelpubnt:~# mv composer /usr/local/bin/

Next check the composer command.

root@linuxhelpubnt:~# composer



Run from normal user like below.

Tag : Ubuntu
Comment
canmargarini
Nov 14 2017
btw, I had to make the file executable with: sudo chmod x composer
Add a comment
FAQ
Q
What does composer do?
A
Composer is a dependency management tool for PHP similar to npm for nodejs and bundle for ruby
Q
What version of PHP should be installed ?
A
Anything above PHP 5 and above verisions aslo can be installed in the PHP
Q
How to install Composer to a specific directory in composer?
A
By using this coomand to install
"php composer-setup.php --install-dir=bin --filename=composer"
Q
How to install the manuualy with phar?
A
Change to a directory on your PATH and run the installer download composer.phar.

Create a new composer.bat file alongside composer.phar:
Q
How to check Version of the composer?
A
You can check by using this command
" composer -V"