Using Drush in a MAMP environment
Drush is one of those tools you want nearby when working on Drupal. Installing it inside a local MAMP setup can be a little awkward, though.
I had to set it up again after a fresh MAMP Pro install, so here are the steps.
Make MAMP's PHP binary the default one
When you install MAMP on a Mac, you usually end up with more than one PHP binary. macOS ships with its own Apache/PHP setup, and that is the one your terminal may use by default. For Drush, you want the command line to use MAMP's PHP instead.
You can do that by changing your PATH. First, check the current value:
echo $PATH
The output should look something like this:
/sbin:/usr/local/bin:/usr/X11/bin
MAMP Pro came with PHP 5.2.17 and 5.3.6. I wanted version 5.3.6 to be the default one in the terminal. Edit ~/.bash_profile:
sudo vi ~/.bash_profile
Make sure this line exists:
PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.3.6/bin:$PATH
This puts MAMP's PHP 5.3.6 binary before the other PHP binaries on the system.
Now run which php in the terminal. You should see something like this:
/Applications/MAMP/Library/bin
Install Drush through PEAR
MAMP's PEAR includes a config file that can cause strange issues. I had already hit this earlier and fixed it by running:
rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf
Next, install the console_getopt PEAR module:
pear install Console_Getopt
Now install Drush:
bash$ pear upgrade --force Console_Getopt$ pear upgrade --force pear$ pear upgrade-all$ pear channel-discover pear.drush.org$ pear install drush/drush
To check if everything works, run:
drush version
If the install worked, you should see drush version 5.4.