Octave for macOS: Difference between revisions

From Octave
Jump to navigation Jump to search
(→‎Simple Installation Instructions: Since many beginners might want a GUI, corrected the instructions for installing with it.)
Line 143: Line 143:


This would install octave with the default dependencies.  
This would install octave with the default dependencies.  
The default charting package in Octave is straight qt. However, on the Mac gnuplot often works better. To set up gnuplot, install (or reinstall) it with qt enabled:
<pre>brew install gnuplot --with-qt</pre>
Then configure Octave to use it by placing the following text in your ~/.octaverc file:
<pre>setenv('GNUTERM','qt')
graphics_toolkit("gnuplot")</pre>


Note: If brew complains about:
Note: If brew complains about:

Revision as of 20:43, 14 October 2018

GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. GNU Octave for Mac OS X is readily available using package managers such as Fink, MacPorts, and Homebrew.

About version numbers (as of July 2018):

  • The 4.4.x are current releases.
  • The 4.2.x are previous releases.
  • The 4.0.x or earlier are very old releases.

Installing a Mac OS X Bundle

Good progress has been made on creating a reliable App bundle for Octave on Mac OS X. Approaches using MacPorts and Homebrew have been considered.

To compile and create the application bundle yourself, see the instructions on how to create the bundle using Homebrew. (See instructions on how to create a bundle using Macports for reference, but this approach is not currently being used.)

Octave 4.2.2 VM installer for Mac OS X 10.10 Yosemite, 10.11 El Capitan, 10.12 Sierra, 10.13 High Sierra

Point and click configuration files that cause Vagrant to automatically download and configure an Octave 4.2.2 server VM under OS X including 10.10 Yosemite, 10.11 El Capitan, 10.12 Sierra and 10.13 High Sierra. The install process pulls down Octave 4.2.2 from the repository. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave GUI and graphics will display seamlessly on the Mac via the Mac's native X-windows server, while the server runs headless.. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.

Binary installer for OSX 10.9.1

A binary installer for Mavericks can be found on Octave Forge.

This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under

 /usr/local/octave/3.8.0 

And will create two entries in the Applications folder

/Applications/Octave-cli.app 
/Applications/Octave-gui.app 

Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder.

If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.

You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on this page in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper".

In short:

  • In Finder, Control-click or right click the icon of the app.
  • Select Open from the top of contextual menu that appears.
  • Click Open in the dialog box. If prompted, enter an administrator name and password.

This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.

Manual Installation from Source

The page Octave for Mac provides minimalistic instructions for building Octave from source on Mac OS X. Additional support for those who need assistance in building Octave is available.

Package Managers

A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites. Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database. Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.

There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using package managers such as Fink, MacPorts, and Homebrew.

The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.

Xcode Dependency

Each package manager requires that Xcode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the Mac OS X gcc Installer by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's Xcode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with Xcode already installed avoid installing Kenneth's solution, as it may break your existing Xcode installation.

  • Fink: The Mac OS X gcc Installer has not been tested.
  • MacPorts: The Mac OS X gcc Installer has not been tested.
  • Homebrew: The Mac OS X gcc Installer has not been tested.

Fink

The Fink project is an effort to port and package open-source Unix programs to Mac OS X. Fink uses dpkg and APT (Debian's package management system), as well as its own frontend program, fink (which is implemented as a set of Perl modules).

Simple Installation Instructions

  • Install Xcode via the Mac App Store.
    • Once installed, install the Command Line Tools from Xcode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use sudo xcode-select --install on 10.9 or 10.10 .
  • Follow Fink's installation instructions. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, Fink Commander.
  • Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is here. To install the latest Octave with GUI support, type fink install octave-qtmac or fink install octave-qtx11 at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that octave-atlas-qtmac or octave-atlas-qtx11 be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.
  • Fink should also be used to install [packages for Octave. For example, the control systems package may be installed by typing fink install control-atlas-oct382 at a terminals command line.

For the doc() function to be supported by Octave, either the unversioned octave, octave-atlas, or octave-ref package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.

MacPorts

MacPorts, formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS X and Darwin operating systems. It is a free/open source software project to simplify installation of other free/open source software. Similar in aim and function to Fink and the BSDs' ports collections, DarwinPorts was started in 2002 as part of the OpenDarwin project, with the involvement of a number of Apple Inc. employees including Landon Fuller, Kevin Van Vechten, and Jordan Hubbard.

Following instructions are made for MacPorts 2.3.4 on Mac OS X 10.11 (El Capitan) and GNU Octave 4.0.3 in the first place:

MacPorts Installation

You have to install MacPorts prior to the Octave installation anyway.

  • Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools" as described at MacPorts' installation instructions.
  • Install the appropriate MacPorts version for your OS X version. If you had installed Mac Ports in the past already, update it first by typing sudo port selfupdate and sudo port upgrade outdated in the terminal.

Basic Installation Instructions

  • Now an Octave installation should work with sudo port install octave out-of-the-box but for some reasons the next lines are worth reading.
  • If you decide to do the custom Octave installation ignore the point above and go to the next chapter. The custom installation will consume more (compilation) time. The basic installation may work for the most users.

Custom Installation Instructions

For best performance, variability and reliability the custom installation is suggested.

Preliminary Port Installations

  • The new Octave 4 port relies on the accelerator variant. Unfortunately this variant is known for some problems (see below). A better alternative is the "atlas" port, it is necessary to build it with the here specified variant prior to the Octave port installation: sudo port install atlas +gcc5. This can last for many hours. Do this overnight. If a prior atlas installation failed, do sudo port clean atlas before reinstallation.
  • Octave depends on arpack, too. Unfortunately arpack is installed with the accelerate variant by default. The accelerate variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the atlas variant instead of the accelerate variant sudo port install arpack -accelerate+atlas. You can even do this after you installed Octave. The new variant become active by default.

Octave Installation

  • MacPorts has good support for Octave. A list of what MacPorts has available for Octave is here. To install the most recent version of Octave, type sudo port install octave -accelerate+atlas at the Terminal's command line. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take some time.
  • Note that octave-devel has been replaced by octave, see MacPorts Revision 114034.
  • The variant installed may be important to the user's experience. The available variants for octave are displayed by typing port variants octave. In MacPorts 2.3.4 the variants accelerate, app, docs, fltk, gfortran, graphicsmagic, qt4gui and sound are installed by default (marked with '+' sign in port variants octave output). If you need Java support add the new Java variant (+java). A installed Java JRE is mandatory. Go To the Oracle Java website for Download. The following command works fine: sudo port install octave -accelerate+atlas+java
  • If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type graphics_toolkit('gnuplot') in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type setenv("GNUTERM","wxt") in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your ~/.octaverc. To close the graphic window of gnuplot use the Octave command close() to get rid of the Gnuplot instance instead of using the close button of the window.
  • The first plot after startuing Octave 4 can last a while.

Detailed Installation Instructions

To get detailed instructions from start to end on one page, refer Hani's Omnium Gatherum.

Update problems

If an update fails you may chosen incompatible variants in a prior installation. See Octave 4 upgrade via MacPorts fails after “port upgrade outdated” for details

Homebrew

Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.

Simple Installation Instructions

First, install Homebrew:

  • Install Xcode via the Mac App Store.
    • For Mac OS 10.9 (Mavericks) install the command line tools by xcode-select --install.
    • For earlier versions of Mac OS, install the command line tools from Xcode's Apple Menu > Preferences > Downloads.
  • Follow Homebrew's installation instructions.
  • If running Mountain Lion (Mac OS 10.8) or later, install XQuartz.

To install Octave, update to the latest package definitions, install gfortran (Now you don't need to install it manually, it would be installed by dependency), and then Octave.

First we ensure brew itself has the latest definitions:

brew update && brew upgrade octave

Then, we install Octave. To install only the command-line version use:

brew install octave

To install Octave with the Qt GUI, install qt then install Octave --with-qt:

brew install qt
brew install octave --with-qt

This would install octave with the default dependencies.

The default charting package in Octave is straight qt. However, on the Mac gnuplot often works better. To set up gnuplot, install (or reinstall) it with qt enabled:

brew install gnuplot --with-qt

Then configure Octave to use it by placing the following text in your ~/.octaverc file:

setenv('GNUTERM','qt')
graphics_toolkit("gnuplot")

Note: If brew complains about:

Linking /usr/local/Cellar/ghostscript/9.14...
Error: Could not symlink share/ghostscript/Resource
/usr/local/share/ghostscript is not writable.

This is telling you the user permissions for ghostscript are not setup in a way that your user profile can use. You need to change those permissions to your user profile. The following command will repair the issue:

sudo chown -R `whoami` /usr/local/share/ghostscript
brew link --overwrite ghostscript

Then run the brew install command again for octave.

Note: If brew complains about not having a formula for octave, the following command should fix it:

brew tap --repair

The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:

brew update && brew upgrade

Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.

Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.

You might find that you need to add:

setenv ("GNUTERM", "X11")

to your octaverc file, normally located at /usr/local/share/octave/site/m/startup. See also brew info octave for recommended settings.

In case of trouble, see the Homebrew Troubleshooting Guide, which assists in diagnosing problems and craft useful bug reports. The post by Jatin Ganhotra may also be helpful. Bugs may be reported at Homebrew-science's issue tracker.

Using Aquaterm with Gnuplot

When using gnuplot as the graphics toolkit, if the aqua terminal is not supported by gnuplot, follow the steps below to resolve the problem.

  • Uninstall gnuplot
brew uninstall gnuplot
brew install gnuplot --with-aquaterm --with-qt

Create a launcher app with AppleScript

  • Open the "AppleScript Editor" application
  • write the following text in the editor window:
tell application "Terminal"
 do script "/path/to/octave; exit"
end tell

or if Octave is in your default path:

tell application "Terminal"
 do script "`which octave`; exit"
end tell

or if you wish to start the GUI by default, without a terminal:

do shell script "/path/to/octave --force-gui"

(e.g. Homebrew installs Octave to '/usr/local/bin/octave' by default)

  • Select "Save as ..." from the "File" menu
  • In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"

To change the application icon

  • Open this link in a web browser, right-click and select "copy image".
  • Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.
  • In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.