← Other topics

Install Composer on a Mac - PHP dependency management

Video Notes

Composer is a command line based program used to manage dependencies in PHP projects.

To install Composer on a Mac, first move into your /usr/local/bin directory. This is a common location to put command line executable programs, so we’ll install Composer here.

> cd /usr/local/bin

Note: On some versions of OSX the /usr directory does not exist by default. If you receive the error /usr/local/bin: No such file or directory then you can create the directory using this command:

> sudo mkdir -p /usr/local/bin

Once in /usr/local/bin, run the following command to download the Composer installer and run it using php:

> sudo curl -sS https://getcomposer.org/installer | sudo php

After running the above command you should see a message saying that Composer was successfully installed:

> curl -sS https://getcomposer.org/installer | sudo php
Password:
All settings correct for using Composer
Downloading...

Composer successfully installed to: /usr/local/bin/composer.phar
Use it: php composer.phar

The resulting program (composer.phar) has a .phar (PHP Archive) extension. We can shorten this by renaming it to just composer:

> sudo mv composer.phar composer

Now we have a simple, terse command to invoke Composer. Test it out:

> composer

Invoke Composer from any directory

If you’re in a directory other than the one in which Composer was installed, you may run into an error telling you that Composer can not be found.

This will happen if the /usr/local/bin path is not in your computer’s PATH variable which contains a list of directories your system will check for commands/programs when invoked.

To address this, follow this guide: PATH Variable (Mac)

If this info helped you out, toss a coin in the tip jar?
← Other topics