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.