Installing Octave 4.2.1 on macOS Sierra

I’ve been using version 4.0.3 of Octave for some time, installed via the binary available from SourceForge. It works reasonably well, with the exception of having to return to Terminal to enter commands for paged output. I wanted to move up to the current version and managed to get version 4.2.1 installed using HomeBrew. In case you are interested, here are the steps I followed:

Open Terminal

Enter the command: /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

Press RETURN

Install homebrew/science using the following command: brew tap homebrew/science

Octave requires XQuartz, install using: brew cask install XQuartz

Install Octave using the following command: brew install octave

Wait for a bit, then installation finishes

At this point, I “cd’ed” to the bin directory and attempted to run Octave with the following command:

cd /usr/local/Cellar/octave/4.2.1_2/bin/
./octave

Sadly, this produced the following error:

dyld: Library not loaded: /usr/local/opt/hdf5/lib/libhdf5.100.dylib
Referenced from: /usr/local/Cellar/octave/4.2.1_2/libexec/octave/4.2.1/exec/x86_64-apple-darwin16.5.0/octave-gui
Reason: image not found
octave exited with signal 6

After some poking around Brew’s install of Octave, I noticed the library in question (located at: /usr/local/opt/hdf5/lib/) had been updated to version 101 (libhdf5.101.dylib), instead of the expected 100 version. I also noticed there was a symlink from libhdf5.dylib to libhdf5.101.dylib. So I just duplicated that symlink, renamed it libhdf5.100.dylib and reran the ./octave command. Everything works!

P.S. I made a small text file that contains the following:

#!/bin/bash
# Runs Octave 4.2.1

/usr/local/bin/octave

and saved it to the Desktop with the filename Octave.command. Then in Terminal, I made it executable by running the following: chmod +x Octave.command

You can now double-click this file to run Octave!