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
/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
> sudo mv composer.phar composer
Now we have a simple, terse command to invoke Composer. Test it out: