DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Alexander Omorokunwa
Alexander Omorokunwa

Posted on • Originally published at fossnaija.com on

HOW TO INSTALL COMPOSER ON LINUX

how too install composer banner

Composer is a command-line package manager for the PHP programming language. Composer helps in managing dependencies and libraries that are required when developing PHP applications.

Soif you’re developing a PHP app and you need some third-partylibraries you can declare them in the β€œ_ composer.json _”file; while composer will go ahead to install the libraries andupdate them for you as necessary.

Thesepackages are installed in a directory like β€œvendor within yourproject directory

Composer will manage the libraries of different PHP projects individually; because definitely different project need different packages or even none at all.

In this post, I would show you how you can install composer on Ubuntu Linux. Similar steps can be followed with other distros of Linux.

Requirements

Foryou to be able to run/use composer you must have PHP(version5.3.2 and above) installed in your system.

Checkhere on how to installPHP on your system.

Step1 – Update systems software repositories:

Usethe command:

sudo apt-get update

Step2 – Then go to the home directory:

cd ~

Step3 – Download composer:

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

Step4 – Verify the installer

Nowverify that the installer you just downloaded is the same with thelatest version using the SHA-384 hash.

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

Ifsuccessful, you should have a β€œInstallerverified”as output.

composer install commands
Composer installation commands.

Step5 – Install composer:

Thereare two ways to install Composer. Locally as part of your project, orglobally as a system wide executable.Except on very important reasons, it is advisable to install itglobally on your system. And thats what we will do here (i.e. In the/usr/local/bin directory);

sudo php composer-setup.php --install-dir=/usr/loacal/bin --finame=composer

Theoutput should look like this;

_ Allsettings correct for using Composer _

_ Downloading… _

Composer(Version 1.8.6) successfully installed to: /usr/local/bin/composer

_ Useit: php /usr/local/bin/composer _

You can type this command to launch composer:

composer

You should see this:

running composer
Composer output.

Thereyou have it, composer installed in your system.

Happy Linux’NG!

The post HOW TO INSTALL COMPOSER ON LINUX appeared first on Foss Naija.

Top comments (1)

Collapse
 
bijaykumarpun profile image
Bijay Kumar Pun • Edited on

A little typo in 'sudo php composer-setup.php --install-dir=/usr/loacal/bin --finame=composer' had me confused for a second.
Otherwise a great article, and I actually followed.
Thanks!
Edit:
This doesn't work as intended due to all the typos

Hacktoberfest is happening now!



It is a month-long celebration of open source. For a lot of devs, its their introduction to open source.


Check out the Hacktoberfest tag on DEV to keep up with the latest!