How to install composer on mac os

Step 1 – Copy the following commands

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" 
php composer-setup.php 
php -r "unlink('composer-setup.php');"
These commands will do the following;
  • Download the installer to the current directory
  • Verify the installer SHA-384, which you can also cross-check here
  • Run the installer
  • Remove the installer

Step 2 – Open your terminal and paste the commands that you copied in our first step. Wait until it finishes.

In the directory where you run these commands, a file named “composer.phar” will be created. This is the “Composer” that we will be using on our PHP projects. We need to move this to a location where we can call it anywhere. If you try to run “composer”, nothing will happen yet.

Step 3 – Make “composer.phar” global by executing the command listed below on your Terminal

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

This will move the composer.phar to the specified folder. If you run “composer” it will now display its help screen which means that we can now run composer anywhere.