Igor Simic
3 years ago

How to install composer on Mac OS machine


In order to install and use any PHP package, library of framework the best way is to use composer. Composer is command line tool which can download and install PHP packages in your application.Updating or removing these packages can also be done by composer.

How to install composer globally on your Mac OS machine

1. download composer:
  • curl -s https://getcomposer.org/installer | php
2. install it globally
  • sudo mv composer.phar /usr/local/bin/composer


Now you can type composer --version in your terminal and you should get the version which means that  composer is successfully installed:
composer --version

//output -> Composer version 1.6.3 2018-01-31 16:28:17

So the first after install, you should try to update composer to latest version by using this command:
composer self-update
Now you can find your package and install it!

The best way is to navigate to your folder in terminal and then call composer. 
Example of installing Facebook SDK for PHP
composer require facebook/graph-sdk
To use this library in your project you have to include vendor/autoload.php which will load your composer dependency:
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

Here is another example of using composer for installing laravel:
https://www.coditty.com/code/composer-commands