Painless installation of SML on OS X

Dom Habersack
Dom HabersackJuly 30, 2012

Are you learning SML/NJ in college? I recorded some free beginner videos that explain how it works. Go to the course →

Studying Computer Science of any kind, you will be asked to install a wide range of software you will use for one semester and are unlikely to ever need again afterwards.

SML/NJ is a popular choice in functional programming lectures, but since it is not incredibly widespread, installing it can be a hassle. You could follow their official installation instructions, but you will end up with bits and pieces of it scattered throughout your entire system with little hope of ever getting rid of the entire thing.

Installing SML/NJ through Homebrew

The Homebrew package manager makes installing SML/NJ on OS X not only much easier, but it will also uninstall all of SML when you are done with it, leaving no dead files on your system.

To install SML/NJ through Homebrew, just follow these steps.

Install/update Homebrew

Installing Homebrew is a one-liner, which you can find in their GitHub wiki. The command you need to run is:

$ ruby <(curl -fsSk

(Check their wiki if this command fails for you in case they changed it since.)

If you already have Homebrew installed on your system, make sure it is up to date:

$ brew update

Install/update Xcode

Install Xcode or make sure you are running at least Xcode 4.3.3. Both installation and update are available through the Mac App Store. Xcode is a free download.

Install Command Line Tools

Start Xcode, then go to “Preferences… - Downloads - Components” and install the “Command Line Tools”.

Install SML/NJ

Now you are all set and can install SML/NJ through Homebrew:

$ brew install smlnj

Update your PATH

Once SML is installed, you need to tell the operating system where to look for it. Edit your PATH to include /usr/local/Cellar/smlnj/110.74/libexec/bin. (Note that the exact path to use has been given to you after the installation, so yours might be slightly different from this one.)

First, open your profile in your text editor of choice:

$ open -t ~/.bash_profile

Add an export PATH-directive to this file:

export PATH=/usr/local/Cellar/smlnj/110.74/libexec/bin:$PATH

You can now reload your profile with:

$ source ~/.bash_profile

Your new PATH will also be loaded every time you open a new terminal session.

Now that you are all done, you can start SML/NJ by typing:

$ sml

One more thing

You are probably reading this article because you are currently attending a lecture on functional programming at the LMU in Munich, Germany. If so, these screencasts on SML I created while attending this lecture myself should help you hit the ground running.