Painless installation of SML on OS X

Posted on (updated Sep 19, 2023)

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 on brew.sh. The command you need to run is:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

(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
$ 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
$ 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
$ open -t ~/.bash_profile

Add an export PATH-directive to this file:

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

You can now reload your profile with:

$ source ~/.bash_profile
$ 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
$ 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.

Debug
none
Grid overlay