Composer is a cross-platform dependency manager for PHP libraries.
In this guide, i'm installing Composer on a machine running Mac OSX with MAMP.
- Open a terminal and navigate to your user directory, ie cd /User/<USER_NAME>/
- Run this command shown below to download Composer. This will create a Phar (PHP Archive) file called
curl -sS https://getcomposer.org/installer | php
- Now we move
composer.phar fileto a directory
sudo mv composer.phar /usr/local/bin/
- We want to run Composer with having to be root al the time, so we need to change the permissions:
sudo chmod 755 /usr/local/bin/composer.phar
- Next, we need to let Bash know where to execute Composer:
Add this line below to bash_profile and save
alias composer="php /usr/local/bin/composer.phar"
and then run this command:
- Finally, run:
If all goes well and it is working, you'll see this screen:
Updated this post on 7 Dec 2020
Composer version 2 has been released for a few months now. Since i upgraded Drupal 9 to 9.1, it recommends to use Composer 2. So i thought it might as well be time to upgrade. The benefits it brings is that it is supposed to be much faster.
If you have already installed Composer 1 and feel it is time to upgrade, the process is really simple. First, update to latest version. Type and run:
If you run composer self-update again, you will see this message:
To upgrade to Composer 2.x from older version, type and run:
composer self-update --2
While using Composer 2.x and you are experiencing some issues using it with your project, you can always downgrade back to 1.x version. To do this, type and run:
composer self-update --rollback
Note: When you try to upgrade Drupal 9 with composer 2. You will get this error:
- oomphinc/composer-installers-extender[v1.1, ..., v1.1.2] require composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
- Root composer.json requires oomphinc/composer-installers-extender ^1.1 -> satisfiable by oomphinc/composer-installers-extender[v1.1, v1.1.1, v1.1.2].
What you will need to do first is to update the plugin (composer installer extender). To do this, open your your composer.json file and change this line to use ^2.0 version:
Now you can try and run:
"# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
# <<< conda initialize <<<"
FYI for anyone working on a newer Mac OS, terminal prefers ZSH as its default shell (instead of Bash). That means that a couple of lines change because you write the alias to .zshrc instead of .bash_profile:
And, pay attention to where the composer.phar file was saved. It might not be at /usr/local/bin...