Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stephenmckinney/1916262 to your computer and use it in GitHub Desktop.
Save stephenmckinney/1916262 to your computer and use it in GitHub Desktop.
Instructions on how to setup an OSX developer machine for (python/django/ruby/rails) development

OSX Developer System Installation

This guide assumes you are upgrading from Mac OSX 10.6 Snow Leopard to 10.7 Lion.


Starting Clean

Uninstall XCode

sudo /Developer/Library/uninstall-devtools –mode=all

Uninstall Homebrew

Follow https://github.com/mxcl/homebrew/wiki/FAQ/ under "How do I uninstall Homebrew?"

Uninstall RVM

rvm implode

Uninstall Old Python libraries

No action needed. Previous python libraries installed to /Library/Python/2.x/site-packages/ have all been removed by the upgrade to Lion.

Remove dot cruft

Use at your own risk.

rm -rf .cabal
rm -rf .gem
rm -rf .npm
rm -rf .ghc
rm -rf .passenger
rm -rf .pip
rm -rf .python-eggs

Install XCode

There are two options:


Install Homebrew

See https://github.com/mxcl/homebrew/wiki/installation for details.

Install Homebrew (as of 3/30/3012):

/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

Add Homebrew to your path in ~/.zshenv or ~/.bash_profile:

export PATH=/usr/local/bin:$PATH

Open a new terminal window or source the above file.

Then install the basics:

brew install git ack wget tree ctags

Install Ruby and friends

Install Ruby 1.9.3+

See http://beginrescueend.com/rvm/install/ for details.

Install RVM:

bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

Add RVM toyour ~/.zshenv or ~/.bash_profile:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Open a new terminal window or source the above file.

Install Ruby 1.9.3 and make it your default:

rvm install 1.9.3
rvm use 1.9.3 --default

Check your Ruby version and bin for good measure:

ruby -v
which ruby

You should see something similar to the following:

ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
/<home>/.rvm/rubies/ruby-1.9.3-p125/bin/ruby

Then install the basics:

gem install bundler capistrano hpricot pry pry-doc rspec rails

Install older Rubies (e.g. Ruby 1.8.7)

The latest XCode and XCode Command Line Tools changes the default compiler from gcc to the llvm compiler. Only ruby-1.9.3-p125+ is LLVM ready. So, you will have to install gcc-4.2 to compile older versions of Ruby. More detail here https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers. This worked for me:

brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb CC=/usr/local/bin/gcc-4.2 rvm install 1.8.7

Install Python and friends

See https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python and https://github.com/mxcl/homebrew/wiki/Gems%2C-Eggs-and-Perl-Modules for details. The brew will install Python 2.7 and Distribute. Yes, Lion comes with Python 2.7 but this makes it dead simple to upgrade or remove in the future.

Python, pip, virtualenv:

brew install python
/usr/local/share/python/easy_install pip
/usr/local/share/python/pip install --upgrade distribute
/usr/local/share/python/pip install virtualenv

homebrew sets things up so that all packages installed via python setup.py install, easy_install or pip get their commands installed to /usr/local/share/python/ by default (see the above link for an explanation). So the first rule of business is to add that path to your PATH. Also if you want to use your homebrew python (and other homebrew stuff) by default, /usr/local/bin should be all the way at the front of your PATH.

Go back to your ~/.bash_profile or ~/.zshrc and change the PATH to include /usr/local/share/python:

export PATH=/usr/local/bin:/usr/local/share/python:$PATH

NOTE: remember to open a new terminal or call source ~/.bash_profile in all of your open terminal windows to get PATH updated.

Before installing stuff with pip, make sure the above PATH changes worked and you are using the correct version:

pip --version

should return something like (a path with /usr/local/)::

pip 1.1 from /usr/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg (python 2.7)

Install PIL

Install some dependencies::

brew install jpeg
brew install libtiff
brew install little-cms

If you don't need FREETYPE support, the regular pip install PIL will work. There is no real need to install PIL globally then. If you need FREETYPE, choose one of these three options. I recommend Pillow.

Option #1: Pillow (Recommended)

Pillow is an alternative Distribution of PIL (Personally, I only install this into my virtualenv):

pip install Pillow

Pillow does a great job of finding all the dependencies it needs in OSX. But it sucks a bit if an other packages list PIL as a dependency, because Pillow will not be recognized as a valid PIL installation and PIL will be installed again.

Option #2: PIL globally with homebrew

Homebrew has a formula for PIL::

brew install pil

.. WARN:: This may produce the dreaded AccessInit: hash collision: 3 for both 1 and 1 error if some apps import PIL as from PIL import Image and others as import Image.

Option #3: PIL with patching setup.py

Since PIL is not packaged correctly, setup.py needs to be tweaked.

Use the newest version of PIL from http://www.pythonware.com/products/pil/ and edit FREETYPE_ROOT = ("/usr/x11/lib","/usr/x11/include",) in setup.py. Then::

python setup.py build_ext -i
python setup.py install

Note on PIL compatibility:

Some python packages don't work when PIL is installed with the PIL prefix. Add a PIL.pth file in /usr/local/lib/python2.7/site-packages/PIL.pth containing the string PIL. Now both from PIL import Image and import Image will work.

This oneliner will do exactly that::

echo "PIL" > /usr/local/lib/python2.7/site-packages/PIL.pth

Install Databases

Install MySQL:

brew install mysql

There are a bunch of instructions to follow post install. Follow the ones that make sense to you.

Personally I don't like databases starting up automatically on system launch so I put the following aliases in my ~/.zshrc:

alias mysqlstart='/usr/local/Cellar/mysql/5.5.19/bin/mysqld_safe &'
alias mysqlstop='/usr/local/Cellar/mysql/5.5.19/bin/mysqladmin -u root -p shutdown'

Install python client binding (Personally, I only install this into my virtualenv):

pip install mysql-python

Install ruby gem (Personally, I would save this to be installed in a per project bundle):

gem install mysql2

Install PostgresSQL:

PYTHON=/usr/local/bin/python  brew install postgresql

There are a bunch of instructions to follow post install. Follow the ones that make sense to you. There are isntructions for upgrading Postgres databases, but rather than upgrading postgres databases I simply deleted my /usr/local/var/postgres and ran initdb /usr/local/var/postgres.

Personally I don't like databases starting up automatically on system launch so I put the following aliases in my ~/.zshrc:

alias postgresstart='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start &'
alias postgresstop='pg_ctl -D /usr/local/var/postgres stop -s -m fast'

Install python client bindings (Personally, I only install this into my virtualenv):

pip install psycopg2

Install ruby gem (Personally, I would save this to be installed in a per project bundle):

gem install pg

Go Hack!

@treevis
Copy link

treevis commented Jun 11, 2012

My old Python libraries have remained after the upgrade to Lion. I have back to 2.3.

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