How to Install PHP Composer in your Mac

Composer is the easiest way to manage dependencies to your small to large PHP projects.

Use the following commands to install composer in your Mac

$ curl -sS | php

Now the composer is installed in your current directory.

Now, you can access it using the following command

$ php composer.phar [command]

It works but you don’t always want to use this directory path to access the composer, So in the next step we will make it accessible globally.

Let us move it to usr/local/bin to make it globally accessible from your terminal.

$ mv composer.phar usr/local/bin

Next, create alias and add it to your bashrc file to load it everytime you restart your terminal or mac book.

$ echo 'alias composer="php /usr/local/bin/composer.phar"' >> ~/.bash_profile

That’s all, Restart your terminal and now try using composer in your terminal and it works. Every time the terminal opens it autoloads this alias now.

Bonus: If it is for other platform such as Ubuntu, you need to write to bashrc instead of bash_profile.

$ echo 'alias composer="php /usr/local/bin/composer.phar"' >> ~/.bashrc

One thought on “How to Install PHP Composer in your Mac

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.