Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

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?

share|improve this question
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. –  stali Jun 8 '12 at 13:19

3 Answers 3

up vote 22 down vote accepted

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.

share|improve this answer
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. –  aterrel Jun 10 '12 at 14:46
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". –  Ondřej Čertík Jun 13 '12 at 18:50
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. –  dmckee Jun 13 '12 at 23:05

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.

share|improve this answer
Have you done testing on OS X? When you say 'should work' is it from experience or expectations? –  Deer Hunter Jan 20 '13 at 6:27
@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. –  Kenneth Hoste Jan 20 '13 at 9:18
Upvoting... Turns out have been using EASY_BUILD to package python goodies into RPMs... –  Deer Hunter Jan 20 '13 at 9:21
@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? –  Kenneth Hoste Jan 20 '13 at 9:26
You are right; random memory failures. Will check out EasyBuild, anyway. Packaging is done by fpm... –  Deer Hunter Jan 20 '13 at 9:29

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.

share|improve this answer
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). –  stali Jun 14 '12 at 0:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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