Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to install Composer globally using MAMP's PHP

##Create an alias to MAMP's PHP installation

To do this, we can simply create an alias for our bash profile. We'll be doing this is nano, though you can do it in vim or a number of other editors as well.

Within the terminal, run:

nano ~/.bash_profile

This will open nano with the contents, at the top in a blank line add the following line:

alias phpmamp='/Applications/MAMP/bin/php/php5.4.10/bin/php'

This will create an alias, phpmamp, so that you can take advantage of the MAMP installation of PHP. Please take note of the PHP version, in this case 5.4.10, as with different versions of MAMP this may be different. Check your installation and see what version you have, and replace the number accordingly (this was written with MAMP version 2.1.2).

With that setup, we are ready to install composer. This is a two step process if we would like this to be installed globally, while you would only need to do the first step if you would like this installed to the local working directory only.

First, run the following command in the terminal:

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

Note that instead of the standard 'php' at the end, we are using 'phpmamp' so that we correctly use the MAMP installation of PHP.

Next, we want to make this available globally, so we need to move the file to '/usr/local/bin/composer'. To do this, run the following command:

sudo mv composer.phar /usr/local/bin/composer

Terminal will ask you for yor password, after entering it and pressing the 'return' (or enter) key, you'll have a working global installation of composer on your mac that uses MAMP!

You can verify your installation worked by typing the following command:

composer

It'll show you the current version and a list of commands you can use!

@kkirsche

This comment has been minimized.

Owner

kkirsche commented Jun 4, 2013

Commands in order:

    nano ~/.bash_profile
    alias phpmamp='/Applications/MAMP/bin/php/php5.4.10/bin/php'
    curl -sS https://getcomposer.org/installer | phpmamp
    sudo mv composer.phar /usr/local/bin/composer
    composer
@veenarm

This comment has been minimized.

veenarm commented Jul 14, 2013

Best installation guide ever!

@micheldenegri

This comment has been minimized.

micheldenegri commented Jul 31, 2013

Thumbs Up ! Thank you for sharing.

@Glenn-Ewing

This comment has been minimized.

Glenn-Ewing commented Aug 3, 2013

Thanks for the simple instructions, made installing very easy!

@eheiser

This comment has been minimized.

eheiser commented Aug 14, 2013

When I run the curl command I get a "zsh: command not found: phpmamp" error. Any suggestions?

@pfandie

This comment has been minimized.

pfandie commented Aug 23, 2013

@eheiser, you can also try

source ~/.bash_profile
@lposen

This comment has been minimized.

lposen commented Oct 9, 2013

This is fantastic. Thank you!

@davidnknight

This comment has been minimized.

davidnknight commented Oct 10, 2013

Also getting "phpmamp: command not found".

@christophfahle

This comment has been minimized.

christophfahle commented Dec 28, 2013

thanks man. helped me a lot!

@mynameisrienk

This comment has been minimized.

mynameisrienk commented Jan 23, 2014

For people who get a command not found error, close down terminal (type "exit") and open a new one... this will reload the bash_profile with the newly added alias.

Also, you can install this globally using the single curl command with an additional installation directory option set:

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/composer/
@cubeguerrero

This comment has been minimized.

cubeguerrero commented Apr 12, 2014

Best Guide ever! thank you for this! :D

@nolros

This comment has been minimized.

nolros commented May 21, 2014

thanks! this worked perfectly!!!

@mehrdd

This comment has been minimized.

mehrdd commented May 23, 2014

Best Guide ever ...
Really !

@andrewayala

This comment has been minimized.

andrewayala commented Jun 28, 2014

Is there a way to point an already-installed Composer to that handy alias? I know you can add the mamp path to the bash-profile export PATH, but I'm afraid that's the deep end of the pool for me.

@dungeonjumper

This comment has been minimized.

dungeonjumper commented Oct 2, 2014

If you've created your alias and are having issues with detecting phpmamp, don't forget to reload .bash_profile after you've added your phpmamp function!

. .bash_profile
@nizlobin

This comment has been minimized.

nizlobin commented Oct 28, 2014

Nice guide! Thanks!

@3zzy

This comment has been minimized.

3zzy commented Dec 9, 2014

I had issues installing:
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to write bundled cacert.pem to: /Users/<username>/.composer/cacert.pem' in -:403

So I did:
curl -sSk https://getcomposer.org/installer | phpmamp -- --disable-tls

It worked!

@kkirsche

This comment has been minimized.

Owner

kkirsche commented Dec 13, 2014

@eheiser this is do to your use of the ZSH shell instead of the bash shell, which is what this installation guide is for. You may be able to use .zprofile instead of .bash_profile to correctly create the alias.

@jfcartier

This comment has been minimized.

jfcartier commented Jan 14, 2015

@Doremidon

This comment has been minimized.

Doremidon commented Apr 7, 2015

thanks a lot!

@jrpsr

This comment has been minimized.

jrpsr commented Jul 8, 2015

Awesome guide. You should add that you need to close the terminal, like mynameisrienk mentioned.
Thanks.

@mldarshana

This comment has been minimized.

mldarshana commented Aug 4, 2015

Here's how I did it
Enter in Terminal:

nano ~/.bash_profile

Then add the following

export MAMP_PHP=/Applications/MAMP/bin/php/php5.5.26/bin
export PATH="$MAMP_PHP:$PATH"

Hit Ctrl + X to save
Then again in Command Line

source ~/.bash_profile

Now you can install Composer by running the following in Command Prompt

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

Finally in Command Line

sudo mv composer.phar /usr/local/bin/composer

Then you should be able to access Composer Global

composer
@harshamv

This comment has been minimized.

harshamv commented Aug 10, 2015

how can i use it with ZSH ?

@logii

This comment has been minimized.

logii commented Aug 13, 2015

@harshamv Your config file to manage ZSH paths should be in ~/.zshrc

@krillo

This comment has been minimized.

krillo commented Aug 30, 2015

In Yosemite 10.10.3 the directory /usr/local/bin doesn't exist. So just create it and then do the copy of the directory. Then Composer works fine globally.

sudo mkdir /usr/local/
sudo mkdir /usr/local/bin

@andrade1379

This comment has been minimized.

andrade1379 commented Sep 11, 2015

I actually have my composer installed globally in the correct directory but what I'm having trouble with is updating it.

My error:

[ErrorException] rename(/Users/MYNAME/.composer/cache/composer-temp.phar,/usr/bin/composer.phar): Permission denied

Here is what I have in my .bash_profile:

# Composer install globally
alias composer="php /usr/bin/composer.phar

I'm I missing something here?

@markmcdermid

This comment has been minimized.

markmcdermid commented Oct 5, 2015

Thanks for this!

@andresmrg

This comment has been minimized.

andresmrg commented Oct 23, 2015

It worked! thank you!

@sairoko12

This comment has been minimized.

sairoko12 commented Nov 9, 2015

Please check the php version in current version MAMP, and begin all use: sudo su

@2webdesign

This comment has been minimized.

2webdesign commented Nov 27, 2015

Best explanation ever!!!

Cheers man.,,,:):):)

@kulemantu

This comment has been minimized.

kulemantu commented Mar 23, 2016

🎉 Appreciation!

@puvanarajan

This comment has been minimized.

puvanarajan commented Mar 24, 2016

Thanks. It is working :)

@smaimon

This comment has been minimized.

smaimon commented May 25, 2016

+1 thank you @kkirsche

@wltrallen2

This comment has been minimized.

wltrallen2 commented Jun 28, 2016

+1 thank you so much! Awesome guide!

@tonypartridge

This comment has been minimized.

tonypartridge commented Jul 6, 2016

+1 Great work. Although even after changing my bash alias it was loading the old php alias directory so I had to setup a system link from php5.4.10 to php5.6.10

@ostrichegret

This comment has been minimized.

ostrichegret commented Oct 28, 2016

This should be the official guide to install composer on OS X,
really nice! It just after adding bash profile, I must close and re-open the terminal.

Thanks a lot @kkirsche

@emiliano1

This comment has been minimized.

emiliano1 commented Dec 23, 2016

@mldarshana great job!

@oraricha

This comment has been minimized.

oraricha commented Feb 11, 2017

Thank you @kkirsche!

@atomicsprite

This comment has been minimized.

atomicsprite commented Mar 14, 2017

@kkirsche / @mynameisrienk thanks guys, now the learning begins!

@tartuzet

This comment has been minimized.

tartuzet commented Mar 20, 2017

Thanks, ,great guide

@wouterstandaert

This comment has been minimized.

wouterstandaert commented Apr 4, 2017

From the docs:

Note: If the above fails due to permissions, you may need to run it again with sudo.
Note: On some versions of OSX the /usr directory does not exist by default.
If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create the directory manually before proceeding:

sudo mkdir -p /usr/local/bin

@ramjamx

This comment has been minimized.

ramjamx commented Apr 25, 2017

Great!,
For people using zshrc steps are the same incluiding
source ~/.zshrc

after
nano ~/.zshrc

Thank you for this guide.

@jasonglisson

This comment has been minimized.

jasonglisson commented May 23, 2017

I keep getting:
-bash: phpmamp: command not found curl: (23) Failed writing body (0 != 16384)

I've checked ~/.bash_profile and everything looks right. Any ideas?

@gitMomo

This comment has been minimized.

gitMomo commented Jun 4, 2017

i have the same errors than jasonglisson ...

@MavenConsulting

This comment has been minimized.

MavenConsulting commented Jun 27, 2017

jasonglisson & gitMomo. Once you've added the alias, close down terminal (type "exit") and open a new one... this will reload the bash_profile with the newly added alias as per mynameisrienk comment on Jan 24, 2014 (Although his single curl command didn't work for me). Then continue the process. I was having the same problems, this seemed to fix it for me.

@GESUMAYOR

This comment has been minimized.

GESUMAYOR commented Jul 11, 2017

Helped a lot. Thanks and many thumbs up. Saved my ass

@ibrahimtumukunde

This comment has been minimized.

ibrahimtumukunde commented Aug 17, 2017

thank You so much.

@flexscss

This comment has been minimized.

flexscss commented Aug 22, 2017

For zsh
alias -g phpmamp='/Applications/MAMP/bin/php/php5.6.10/bin/php'

@zrshishir

This comment has been minimized.

zrshishir commented Oct 21, 2017

After installation when i run 'composer' then it says '-bash: composer: command not found', why ? I can't install composer for this reason.

@KajeNick

This comment has been minimized.

KajeNick commented Dec 2, 2017

Thanks! Were helpful post!

@hestalabs

This comment has been minimized.

hestalabs commented Dec 25, 2017

Its awesome thanks a lot.

Users who are getting error -bash: phpmamp: command not found curl: (23) Failed writing body (0 != 16384) need to source .bash_profile. use this command source ~/.bash_profile

@digeek

This comment has been minimized.

digeek commented Feb 23, 2018

thanks

@TheBigSteph

This comment has been minimized.

TheBigSteph commented Mar 13, 2018

Thanks

@StonehengeCreations

This comment has been minimized.

StonehengeCreations commented Jul 14, 2018

Okay, with all the comments I lost track...
On Mac OSX High Sierra /usr/local/bin doesn't exist. I created it: sudo mkdir /usr/local/bin/composer

I rerun Terminal, run the commands, get no errors.
Still composer does not work. "Command not Found".

Please help.

@scorchio

This comment has been minimized.

scorchio commented Jul 23, 2018

Superb guide, thank you!

@StonehengeCreations - make sure that /usr/local/bin is part of your PATH environment variable. You can set this in your .bash_profile.

@brokenmachine

This comment has been minimized.

brokenmachine commented Sep 7, 2018

Many thanks for creating this!

@ThomRockwell

This comment has been minimized.

ThomRockwell commented Oct 11, 2018

Wonderfully simple! Thanks so much!

@anabrownee

This comment has been minimized.

anabrownee commented Nov 4, 2018

thanks, this worked like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment