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.

Show comment
Hide comment
@kkirsche

kkirsche 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
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.

Show comment
Hide comment
@veenarm

veenarm Jul 14, 2013

Best installation guide ever!

veenarm commented Jul 14, 2013

Best installation guide ever!

@micheldenegri

This comment has been minimized.

Show comment
Hide comment
@micheldenegri

micheldenegri Jul 31, 2013

Thumbs Up ! Thank you for sharing.

micheldenegri commented Jul 31, 2013

Thumbs Up ! Thank you for sharing.

@Glenn-Ewing

This comment has been minimized.

Show comment
Hide comment
@Glenn-Ewing

Glenn-Ewing Aug 3, 2013

Thanks for the simple instructions, made installing very easy!

Glenn-Ewing commented Aug 3, 2013

Thanks for the simple instructions, made installing very easy!

@eheiser

This comment has been minimized.

Show comment
Hide comment
@eheiser

eheiser Aug 14, 2013

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

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.

Show comment
Hide comment
@pfandie

pfandie Aug 23, 2013

@eheiser, you can also try

source ~/.bash_profile

pfandie commented Aug 23, 2013

@eheiser, you can also try

source ~/.bash_profile
@lposen

This comment has been minimized.

Show comment
Hide comment
@lposen

lposen Oct 9, 2013

This is fantastic. Thank you!

lposen commented Oct 9, 2013

This is fantastic. Thank you!

@davidnknight

This comment has been minimized.

Show comment
Hide comment
@davidnknight

davidnknight Oct 10, 2013

Also getting "phpmamp: command not found".

davidnknight commented Oct 10, 2013

Also getting "phpmamp: command not found".

@christophfahle

This comment has been minimized.

Show comment
Hide comment
@christophfahle

christophfahle Dec 28, 2013

thanks man. helped me a lot!

christophfahle commented Dec 28, 2013

thanks man. helped me a lot!

@mynameisrienk

This comment has been minimized.

Show comment
Hide comment
@mynameisrienk

mynameisrienk 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/

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.

Show comment
Hide comment
@cubeguerrero

cubeguerrero Apr 12, 2014

Best Guide ever! thank you for this! :D

cubeguerrero commented Apr 12, 2014

Best Guide ever! thank you for this! :D

@nolros

This comment has been minimized.

Show comment
Hide comment
@nolros

nolros May 21, 2014

thanks! this worked perfectly!!!

nolros commented May 21, 2014

thanks! this worked perfectly!!!

@mehrdd

This comment has been minimized.

Show comment
Hide comment
@mehrdd

mehrdd May 23, 2014

Best Guide ever ...
Really !

mehrdd commented May 23, 2014

Best Guide ever ...
Really !

@andrewayala

This comment has been minimized.

Show comment
Hide comment
@andrewayala

andrewayala 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.

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.

Show comment
Hide comment
@dungeonjumper

dungeonjumper 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

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.

Show comment
Hide comment
@nizlobin

nizlobin Oct 28, 2014

Nice guide! Thanks!

nizlobin commented Oct 28, 2014

Nice guide! Thanks!

@3zzy

This comment has been minimized.

Show comment
Hide comment
@3zzy

3zzy 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!

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.

Show comment
Hide comment
@kkirsche

kkirsche 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.

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.

Show comment
Hide comment
@jfcartier

jfcartier commented Jan 14, 2015

@Doremidon

This comment has been minimized.

Show comment
Hide comment
@Doremidon

Doremidon Apr 7, 2015

thanks a lot!

Doremidon commented Apr 7, 2015

thanks a lot!

@jrpsr

This comment has been minimized.

Show comment
Hide comment
@jrpsr

jrpsr Jul 8, 2015

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

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.

Show comment
Hide comment
@mldarshana

mldarshana 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

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.

Show comment
Hide comment
@harshamv

harshamv Aug 10, 2015

how can i use it with ZSH ?

harshamv commented Aug 10, 2015

how can i use it with ZSH ?

@logii

This comment has been minimized.

Show comment
Hide comment
@logii

logii Aug 13, 2015

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

logii commented Aug 13, 2015

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

@krillo

This comment has been minimized.

Show comment
Hide comment
@krillo

krillo 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

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.

Show comment
Hide comment
@andrade1379

andrade1379 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?

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.

Show comment
Hide comment
@markmcdermid

markmcdermid Oct 5, 2015

Thanks for this!

markmcdermid commented Oct 5, 2015

Thanks for this!

@andresmrg

This comment has been minimized.

Show comment
Hide comment
@andresmrg

andresmrg Oct 23, 2015

It worked! thank you!

andresmrg commented Oct 23, 2015

It worked! thank you!

@sairoko12

This comment has been minimized.

Show comment
Hide comment
@sairoko12

sairoko12 Nov 9, 2015

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

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.

Show comment
Hide comment
@2webdesign

2webdesign Nov 27, 2015

Best explanation ever!!!

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

2webdesign commented Nov 27, 2015

Best explanation ever!!!

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

@kulemantu

This comment has been minimized.

Show comment
Hide comment
@kulemantu

kulemantu Mar 23, 2016

🎉 Appreciation!

kulemantu commented Mar 23, 2016

🎉 Appreciation!

@puvanarajan

This comment has been minimized.

Show comment
Hide comment
@puvanarajan

puvanarajan Mar 24, 2016

Thanks. It is working :)

puvanarajan commented Mar 24, 2016

Thanks. It is working :)

@smaimon

This comment has been minimized.

Show comment
Hide comment
@smaimon

smaimon commented May 25, 2016

+1 thank you @kkirsche

@wltrallen2

This comment has been minimized.

Show comment
Hide comment
@wltrallen2

wltrallen2 Jun 28, 2016

+1 thank you so much! Awesome guide!

wltrallen2 commented Jun 28, 2016

+1 thank you so much! Awesome guide!

@tonypartridge

This comment has been minimized.

Show comment
Hide comment
@tonypartridge

tonypartridge 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

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.

Show comment
Hide comment
@ostrichegret

ostrichegret 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

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.

Show comment
Hide comment
@emiliano1

emiliano1 commented Dec 23, 2016

@mldarshana great job!

@oraricha

This comment has been minimized.

Show comment
Hide comment
@oraricha

oraricha commented Feb 11, 2017

Thank you @kkirsche!

@atomicsprite

This comment has been minimized.

Show comment
Hide comment
@atomicsprite

atomicsprite Mar 14, 2017

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

atomicsprite commented Mar 14, 2017

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

@tartuzet

This comment has been minimized.

Show comment
Hide comment
@tartuzet

tartuzet Mar 20, 2017

Thanks, ,great guide

tartuzet commented Mar 20, 2017

Thanks, ,great guide

@wouterstandaert

This comment has been minimized.

Show comment
Hide comment
@wouterstandaert

wouterstandaert 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

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.

Show comment
Hide comment
@ramjamx

ramjamx Apr 25, 2017

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

after
nano ~/.zshrc

Thank you for this guide.

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.

Show comment
Hide comment
@jasonglisson

jasonglisson 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?

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.

Show comment
Hide comment
@gitMomo

gitMomo Jun 4, 2017

i have the same errors than jasonglisson ...

gitMomo commented Jun 4, 2017

i have the same errors than jasonglisson ...

@MavenConsulting

This comment has been minimized.

Show comment
Hide comment
@MavenConsulting

MavenConsulting 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.

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.

Show comment
Hide comment
@GESUMAYOR

GESUMAYOR Jul 11, 2017

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

GESUMAYOR commented Jul 11, 2017

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

@ibrahimtumukunde

This comment has been minimized.

Show comment
Hide comment
@ibrahimtumukunde

ibrahimtumukunde Aug 17, 2017

thank You so much.

ibrahimtumukunde commented Aug 17, 2017

thank You so much.

@flexscss

This comment has been minimized.

Show comment
Hide comment
@flexscss

flexscss Aug 22, 2017

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

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.

Show comment
Hide comment
@zrshishir

zrshishir 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.

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.

Show comment
Hide comment
@KajeNick

KajeNick Dec 2, 2017

Thanks! Were helpful post!

KajeNick commented Dec 2, 2017

Thanks! Were helpful post!

@anshul321

This comment has been minimized.

Show comment
Hide comment
@anshul321

anshul321 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

anshul321 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.

Show comment
Hide comment
@digeek

digeek commented Feb 23, 2018

thanks

@TheBigSteph

This comment has been minimized.

Show comment
Hide comment
@TheBigSteph

TheBigSteph commented Mar 13, 2018

Thanks

@StonehengeCreations

This comment has been minimized.

Show comment
Hide comment
@StonehengeCreations

StonehengeCreations 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.

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.

Show comment
Hide comment
@scorchio

scorchio 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.

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.

Show comment
Hide comment
@brokenmachine

brokenmachine Sep 7, 2018

Many thanks for creating this!

brokenmachine commented Sep 7, 2018

Many thanks for creating this!

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