How to install Octave on OS X

After twice wasting an hour or so installing Octave for the Stanford Machine Learning class, I decided I should jot this down for posterity or anyone else in a similar position. This should give you a working Octave install that plays nice with Gnuplot. (Most of this comes from Octave’s wiki with help from a StackOverflow post or two.)

Instead of using the Octave installation package as recommended in the course notes (this results in the problems we’re trying to avoid), I’ll be installing Octave via Homebrew, which fixed a lot of my initial install problems.

If you haven’t already, you’ll need to install Xcode (free in the Mac App Store) and the Command Line Tools. Once you’ve installed Xcode, you can install Command Line Tools in Xcode > Preferences > Downloads.

You’ll also need to install XQuartz, so go ahead and download and install that now.

Next, open up a Terminal and do the following:

# install Homebrew if you don't already have it 
/usr/bin/ruby -e "$(curl -fsSL" 

# tap the science formulae
brew tap homebrew/science

# install some Octave dependencies
# the update/upgrade command below could take a while
brew update && brew upgrade
brew install gcc # or 'brew reinstall gcc' if you have an older gcc without gfortran in it

# You may also need to install mactex (see
# The download here takes a while...
brew cask install mactex 
export PATH=$PATH:/usr/texbin

# install X11 
brew cask install xquartz

# install gnuplot
brew install gnuplot --with-x11

# install octave
brew install octave --with-x11

you might need to install legacy Java 6 runtime

Last, you need to edit your .octaverc file to get gnuplot to play nicely with Octave. So, in your home directory, create a new .octaverc file and paste the following:

# ~/.octaverc
setenv ("GNUTERM", "X11")

# below is optional; changes the prompt to two chevron
# and gets rid of the long Octave x.x.x >> prompt
PS1('❯❯ ')

I’m pretty sure that should get you up and running, but in case I missed a step, feel free to send me an email or fix it for me.