fbpx How to install Composer? | DrupalExp - Premium Drupal Themes & Modules

How to install Composer?

Install Composer

1. Installation - Linux / Unix / OSX

The first step is to download Composer, which will effectively create a Phar (PHP Archive) file called composer.phar. From your terminal, run the following command:

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

1.1. Installation Errors

In some cases, you might receive the following error:

Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The detect_unicode setting must be disabled.
Add the following to the end of your `php.ini`:
detect_unicode = Off

A php.ini file does not exist. You will have to create one.
If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times.

For OS X 10.8, the php.ini file should be located in /private/etc/. If you don't have one already, you can copy the default one:

sudo cp /private/etc/php.ini.default php.ini

Then, edit the file and append the following to it:

detect_unicode = Off

Save the file and rerun the curl command above.

1.2. Running Composer

The resulting file will be called composer.phar, a PHP Archive that can be executed directly via PHP. However, in my case, I want Composer to be accessible globally by simply typing composer. To do this, move it to /usr/bin/ and create an alias:

sudo mv composer.phar /usr/local/bin/composer
nano ~/.bash_profile

Add this to your .bash_profile. It may be empty or non-existent, so go ahead and create it:

alias composer="php /usr/local/bin/composer"

Now, relaunch your terminal and you'll be able to access Composer simply by calling composer.

2. Installation - Windows

2.1. Using the Installer

This is the easiest way to get Composer set up on your machine.

Download and run Composer-Setup.exe. It will install the latest Composer version and set up your PATH so that you can call composer from any directory in your command line.

2.2. Manual Installation

Change to a directory on your PATH and run the installer following the Download page instructions to download composer.phar.

Create a new composer.bat file alongside composer.phar:

C:\bin>echo @php "%~dp0composer.phar" %*>composer.bat

Add the directory to your PATH environment variable if it isn't already. For information on changing your PATH variable, please see this article and/or use Google.