Simple Illustrative Tutorial to Install Composer on Mac (OS X)

As I am setting up my mac, I am installing composer on the fresh setup and I decided to write a self documentation on how to setup composer on mac and this might help you as well.

To make sure you don’t have composer already installed go to your terminal and run the following command

composer -v

If already installed you will get the currently installed composer’s version number in the output and if not you will see the error message that says -bash: composer: command not found

bash composer command not found

Livewire Component Library

Perquisite

Make sure you have php installed on your mac osx. The best way to check if you have a valid php running in your machine is to go to command line and run the php -v command.

Host Laravel Application on DigitalOcean

Use coupon 5balloons on this Cloudways Affiliate URL to get special discount.

php -v command mac osx

In the output you should get the php version number installed.

Alright here are the steps to install composer.

Download Composer

The first step in setting up composer is getting composer file on your machine i.e. downloading composer. steps to download are straight-forward and the commands are listed in the official composer website https://getcomposer.org/download/

Open your terminal and run the following commands

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

download composer commands osx mac

As you can see I have downloaded composer version 1.8.4 and its now located in my home directory. The directory from where I executed the download commands.

So now we have installed it locally in the current directory. You can run it from your command line by running command php composer.phar

running composer locally.

But we don’t want to run composer locally, we cant to have it installed globally. So that we can run the composer command from anywhere in your terminal.

Let’s see how we can take this installation global.

Installing Composer Globally

Now, after downloading composer, to run it globally we need to move the composer.phar file to a mac path that is recognized globally.

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

Note: If the above fails due to permissions, you may need to run it again with sudo.

Note: On some versions of macOS the /usr directory does not exist by default. If you receive the error “/usr/local/bin/composer: No such file or directory” then you must create the directory manually before proceeding: mkdir -p /usr/local/bin.

Now you can run command composer directly from terminal instead of running php composer.phar.

installing composer on mac

Site Footer