28
$\begingroup$

Related question: State of the Mac OS in Scientific Computing and HPC

A significant number of software packages in computational science are written in Fortran, and Fortran isn't going away. A Fortran compiler is also required to build other software packages (one notable example being SciPy).

However, Mac OS X does not include a Fortran compiler. How should I install a Fortran compiler on my machine?

$\endgroup$
1
  • 1
    $\begingroup$ Its not just Fortran. Macs simply dont have the high quality supported repositories like Debian where everything just works. Installing pretty much any thing complicated on a Mac is a pain. $\endgroup$
    – stali
    Jun 8, 2012 at 13:19

3 Answers 3

35
$\begingroup$

Pick your poison. I recommend using Homebrew. I have tried all of these methods except for "Fink" and "Other Methods". Originally, I preferred MacPorts when I wrote this answer. In the two years since, Homebrew has grown a lot as a project and has proved more maintainable than MacPorts, which can require a lot of PATH hacking.

Installing a version that matches system compilers

If you want the version of gfortran to match the versions of gcc, g++, etc. installed on your machine, download the appropriate version of gfortran from here. The R developers and SciPy developers recommend this method.

  • Advantages: Matches versions of compilers installed with XCode or with Kenneth Reitz's installer; unlikely to interfere with OS upgrades; coexists nicely with MacPorts (and probably Fink and Homebrew) because it installs to /usr/bin. Doesn't clobber existing compilers. Don't need to edit PATH.
  • Disadvantages: Compiler stack will be really old. (GCC 4.2.1 is the latest Apple compiler; it was released in 2007.) Installs to /usr/bin.

Installing a precompiled, up-to-date binary from HPC Mac OS X

HPC Mac OS X has binaries for the latest release of GCC (at the time of this writing, 4.8.0 (experimental)), as well as g77 binaries, and an f2c-based compiler. The PETSc developers recommend this method on their FAQ.

  • Advantages: With the right command, installs in /usr/local; up-to-date. Doesn't clobber existing system compilers, or the approach above. Won't interfere with OS upgrades.
  • Disadvantages: Need to edit PATH. No easy way to switch between versions. (You could modify the PATH, delete the compiler install, or kludge around it.) Will clobber other methods of installing compilers in /usr/local because compiler binaries are simply named 'gcc', 'g++', etc. (without a version number, and without any symlinks).

Use MacPorts

MacPorts has a number of versions of compilers available for use.

  • Advantages: Installs in /opt/local; port select can be used to switch among compiler versions (including system compilers). Won't interfere with OS upgrades.
  • Disadvantages: Installing ports tends to require an entire "software ecosystem". Compilers don't include debugging symbols, which can pose a problem when using a debugger, or installing PETSc. (Sean Farley proposes some workarounds.) Also requires changing PATH. Could interfere with Homebrew and Fink installs. (See this post on SuperUser.)

Use Homebrew

Homebrew can also be used to install a Fortran compiler.

  • Advantages: Easy to use package manager; installs the same Fortran compiler as in "Installing a version that matches system compilers". Only install what you need (in contrast to MacPorts). Could install a newer GCC (4.7.0) stack using the alternate repository homebrew-dupes.
  • Disadvantages: Inherits all the disadvantages from "Installing a version that matches system compilers". May need to follow the Homebrew paradigm when installing other (non-Homebrew) software to /usr/local to avoid messing anything up. Could interfere with MacPorts and Fink installs. (See this post on SuperUser.) Need to change PATH. Installs could depend on system libraries, meaning that dependencies for Homebrew packages could break on an OS upgrade. (See this article.) I wouldn't expect there to be system library dependencies when installing gfortran, but there could be such dependencies when installing other Homebrew packages.

Use Fink

In theory, you can use Fink to install gfortran. I haven't used it, and I don't know anyone who has (and was willing to say something positive).

Other methods

Other binaries and links are listed on the GFortran wiki. Some of the links are already listed above. The remaining installation methods may or may not conflict with those described above; use at your own risk.

$\endgroup$
5
  • $\begingroup$ There was a time when Fink was the preferred package manager over MacPorts. I stopped using it years ago because the stack was old and not maintained and didn't include many of the libraries I used regularly. With about every method here you end up with some things managed by the package manager and some things you roll by hand. Homebrew is better with such a system, but it needs far more libraries to be really competitive with MacPorts. $\endgroup$
    – aterrel
    Jun 10, 2012 at 14:46
  • 1
    $\begingroup$ You can also use projects like Sage (sagemath.org) or Qsnake (qsnake.com), that ship their own Fortran compiler and allow you to work in "environment", where you can just call "gfortran". $\endgroup$ Jun 13, 2012 at 18:50
  • $\begingroup$ I have fink's gfortran on my 10.5 box, but have never put it to a really serious test. It will compile cernlib and geant3, but I haven't run any big jobs under either lately. $\endgroup$ Jun 13, 2012 at 23:05
  • $\begingroup$ For Homebrew, gfortran is now installed with brew install gcc: $ brew install gfortran gives the message: Error: No available formula for gfortran GNU Fortran is now provided as part of GCC, and can be installed with: brew install gcc $\endgroup$ Mar 17, 2015 at 15:24
  • $\begingroup$ The link to Sean Farley's Wiki page is no longer working (in reference to how to get debuggers to work with MacPorts installs). Can this be relinked? $\endgroup$
    – TSGM
    Feb 4, 2016 at 21:48
1
$\begingroup$

EasyBuild (http://hpcugent.github.com/easybuild) allows you to build and install your own set of GCC compilers easily.

Basically, you give it a simple easyconfig (.eb) file that specifies what you want to build (GCC + version + set of languages you want compilers for + ...), and then building and installing is a single command. I'd say it's a bit like Homebrew, but it gives you more freedom.

Also, EasyBuild supports lots of other (scientific) software packages that can be built and installed with a single command, so it's worthwhile to look into.

Disclaimer: I'm part of the EasyBuild team. Building GCC (with gfortran included) should work on OS X, but other builds may be troublesome. We're working on it, do let us know if you run into trouble.

$\endgroup$
6
  • $\begingroup$ Have you done testing on OS X? When you say 'should work' is it from experience or expectations? $\endgroup$ Jan 20, 2013 at 6:27
  • $\begingroup$ @DeerHunter: From experience, my personal laptop is a Mac, running OS X. Building GCC works, but EasyBuild is known to have problems with some other builds. We hope to look into that soon. $\endgroup$ Jan 20, 2013 at 9:18
  • $\begingroup$ Upvoting... Turns out have been using EASY_BUILD to package python goodies into RPMs... $\endgroup$ Jan 20, 2013 at 9:21
  • $\begingroup$ @DeerHunter EasyBuild currently doesn't have support for packaging stuff into RPMs. Maybe you're confusing EasyBuild (which provides the 'eb' command), with 'easy_install', the Python installation tool that is provided by setuptools/disitutils? $\endgroup$ Jan 20, 2013 at 9:26
  • $\begingroup$ You are right; random memory failures. Will check out EasyBuild, anyway. Packaging is done by fpm... $\endgroup$ Jan 20, 2013 at 9:29
0
$\begingroup$

I would suggest Intel Fortran Composer on MacOS. It's good, up-to-date and works. One negative thing, it's not free. I think there is a 30 days free evaluation though.

Under Linux they offer a free, non-commercial version.

$\endgroup$
1
  • $\begingroup$ Linux users can also install Solaris Studio. It is very well integrated (C/C++/Fortran compilers). Dbxtool is very useful and so is analyzer (e.g. for detecting race conditions in openmp programs). $\endgroup$
    – stali
    Jun 14, 2012 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.