Do you want a good modern development setup? Ruby and Node for all the web goodness and Python with a beautiful ipython console, Numpy, and Scipy for math and statistical computing?
This is the gospel. This is what you will do.
Building blocks: Homebrew, XCode, X11, and Git
This guide is for starting from a fresh Mountain Lion install, with nothing else installed.
You can approximate that state, by getting rid of all your macports and finks and what have you.
Uninstall all XCodes are their developer tools.
ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
Homebrew lets us effortlessly install things from source. It is good, but it needs some help: Mountain Lion doesn’t come with developer tools, and homebrew is not able to do much right now.
Go to the App Store and download XCode (I am writing this in early August 2012, and the current version is 4.4). This can take a little bit, so while it’s downloading, let’s install X11 libraries that Mountain Lion stripped out.
Go here and download 2.7.2+. Install it, and after it’s done, fix the symlink it makes:
ln -s /opt/X11 /usr/X11
When XCode download is done, launch it and go to Preferences, Downloads tab, and install the Command Line Tools. When it finishes, we are almost ready to brew. Before we do, let’s have XCode tell everyone where the tools are (this tip is from Get Mountain Lion and Homebrew to Be Happy ).
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Open up a new shell to make sure everything is loaded from scratch, and check that homebrew is good to go:
Fix the stuff it complains about until it doesn’t.
Now let’s get git:
brew install git
And we are off to the races!
Science stuff: Python and the SciPy stack
We are going to take advantage of a nice man’s labor of love—the Scipy Superpack—to dramatically cut down the time and effort it will take us to get from nothing to a full Matlab and R replacement.
To use it most effectively, we are going to base everything on the system Python, which right now is version 2.7.2. This is 0.0.1 versions behind the latest and greatest, but I think we’ll survive.
Python is best installed through an environment manager.
easy_install pip pip install virtualenv mkdir ~/.virtual_envs virtualenv ~/.virtual_envs/system source ~/.virtual_envs/system/bin/activate
This downloads a package manager, installs virtualenv, duplicates the system environment to a directory in your home directory, and activates this environment.
which python should now show a
Make sure you add the last line to your
Now install the superpack. Since we may want to keep up to date on the exciting scientific python developments, let’s check out the git repository so that we can update faster in the future.
mkdir ~/local && cd ~/local git clone git://github.com/fonnesbeck/ScipySuperpack.git cd ScipySuperpack sh install_superpack.sh
y at the prompt, and that’s it!
The script will install gfortran and binary builds of the latest development versions of Numpy, Scipy, Matplotlib, IPython, Pandas, Statsmodels, Scikit-learn, and PyMC, as well as their dependencies.
Unfortunately, the PySide package installs its stuff into the system python site-packages directory, and our virtualenv ipython doesn’t see it. We could try building PySide from source, but instead we are just going to symlink the relevant stuff from the system to our virtualenv folder. This isn’t very clean, but it works for me.
ln -s /Library/Python/2.7/site-packages/pysideuic $HOME/.virtual_envs/system/lib/python2.7/site-packages ln -s /Library/Python/2.7/site-packages/PySide $HOME/.virtual_envs/system/lib/python2.7/site-packages
Install some remaining dependencies (for some reason, the DateUtils package that the Superpack installs doesn’t work right for me):
pip install pygments pip install dateutils
Now try it out:
ipython qtconsole --pylab=inline
In the qtconsole, try
And enjoy the inline goodness.
Web stuff: Ruby, Node
Ruby is also best installed using an environment manager. Install RVM:
curl -L https://get.rvm.io | bash -s stable
Open up a new shell and let RVM install itself into your bashrc:
Open up another shell and test that it works:
type rvm | head -n 1
rvm is a function.
Now let’s install a version of Ruby. 1.9.3 (the latest version) works fine with the compilers provided by XCode 4.4, so:
rvm install 1.9.3 rvm use 1.9.3 --default
You should be all set now.
For sanity, check that
which bundle shows some
If there are problems, consult the detailed installation guide.
For Node and its package manager, simply
brew install node
Lastly, you may want to install Heroku at some point. I ran into a problem when installing from the Heroku Toolbelt package. Instead, simply
gem install heroku gem install foreman
And you’re done. Good stuff.