1. Download Composer
Head over to the Composer website and copy the install code. It should be 4 lines of code, copy them all. Paste all 4 lines into your terminal.
After running that command, there will be a file
composer.phar in the current directory. You could use that command like this:
php composer.phar install
2. Installing Globally
To make composer available globally, allowing you to type
composer install anywhere, you have to move the recently downloaded composer.phar to local user’s bin folder:
mv composer.phar /usr/local/bin/composer
3. Open your shell profile
What shell are you using?
Using bash? (Default shell on Mac OS <10.14, 2002-2019)
open -e ~/.bash_profile
Using zsh? (Default shell on Mac OS 10.15+, 2019-Present)
open -e ~/.zshrc
4. Add alias to composer
Add an alias to point at the
composer.phar you moved into
.bash_profile add the following line. It will create an alias of
composer that can be used globally.
alias composer="php /usr/local/bin/composer"
5. Use composer globally
After restarting your terminal you will be able to access composer like below:
There are a few ways to accomplish this and an alias method is a simplistic approach. For a more consistent global usage (with other global installs) you should look into adding
/usr/local/bin to your
PATH, see here.