How to install composer on linux

So you need to install composer for one project but you don’t know what is it, what for is it, how to use install it and use it ? Don’t worry you’re on a the right place !

What is composer ?

According to the site :
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.

For simplify, with composer you’ll get access to hundreds libraries to deal with your project.

The time is over when you need to code absolutely all.

With composer you can play at lego with your code.
Need to format phone ? There is a library for that.
Need to work with image ? There is also a library for that.

You will save many hours, trust me.

The must ? With composer you can’t “break” your code.
If a library is incompatible with your project ( ex: your version of php is too old ), she won’t install.

So you’ll have a stable project at any time.

How install composer ?

It’s very simple to install composer. (You need to have PHP installed but i presume this is good for you.)

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

Warning ! Copy paste from composer site and not mine, composer will probably update their version and the hash can change.

Once you have composer.phar, we will move it to be able to use it globally, so in your terminal type.

mv composer.phar /usr/local/bin/composer

To check if it’s ok just type in your cli

composer -V

If you have a message like “composer version 1.x.x” you are good !

Where i can find libraries for my project ?

To find libraries go to :
My advice, work with the libraries who have a good documentation, many downloads and stars, that way you can be sure that they will be update.

Leave a Reply