Install composer globally on Mac OS

Jul 30, 2020
Composer has become an essential part of programmers life these days. The first thing any programmer needs to do before getting a project up and running is to run composer imstall. In this article, we'll take a look at how to install composer globally on Mac OS.

Installing Composer

First things first, we need to install composer if you haven't already. For more information check out composer download page. I am using a Mac therefore the commands shown are for Mac OS. For windows, its a lot easier just download the installer (Composer-Setup.exe) and double click.

Download composer via curl. I usually run this command from within my home ~/ directory but you can do it form any directory.

curl -sS | php

Running the above command will create a composer.phar in the current directory. You can now use composer like so.

php composer.phar install

Installing Composer Globally

To run composer form any directory you need to install it globally. From within the directory where the composer.phar file was downloaded, run the following comand.

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

Add alias for bash ~/.bash_profile

To add an alias open your bash_profile or zshrc and add alias at the end of the file.

sudo vi ~/.bash_profile
alias composer="php /usr/local/bin/composer"

Add alias for oh my zsh ~/.zshrc

sudo vi ~/.zshrc
alias composer="php /usr/local/bin/composer"

Thats it! you should now be able to run composer like so composer init and composer install. Remember to restart your shell before running these commands.