gfortran Install: My View

GCC Install Including gfortran

June 2014, Includes Some Documentation Review and Comments

I was looking for ways of installing gfortran, but everything seems to indicate that 
installing gcc and g++ along with gfortran is a good idea too, since almost every example, 
nightly build, etc. includes the three compilers: gcc, g++, and gfortran... Actually, 
according to ("GCC, the GNU Compiler Collection")
there is a compiler collection, including gfortran, which is referred to as GCC (I think 
it's too close to gcc, the GNU C compiler, but...). 

The home page of gfortran is at
where, near the beginning, the section "The Wiki and Getting the Compiler" points to the 
gfortran wiki, and makes clear the two general ways of obtaining the compiler:
    "The GNU Project is about providing source code for its programs. For convenience, a 
     number of people regularly build binaries for different platforms."
i.e. either in source code or platform-specific binaries. The gfortran wiki, at
has a "Quick links" section, which includes a "Download" title with three options: 
   a) "Binaries for Windows, Linux, MacOS and much more!" 
   b) "Vendor-provided packages for common OS distributions"
   c) "Source c". 
I'm usually not the system manager of the platforms I use (those used in production 
environments), so option b) is rarely useful for me. Also, from a more conceptual point 
of view, I think option b) is a flavor of option a): just "another" binary form.

1.- Install gfortran using binaries

The gfortran wiki refers to the web page "Binaries available for gfortran" at
(from the "Quick links" section at

And the installation using binaries should be simple if you find the corresponding 
"unofficial gfortran binary package" as explained in the web page. Since every computer 
where I use gfortran is Linux, the "GNU/Linux" section is the most useful for me. 
The step-by-step installation of gfortran in a 64-bit Linux is relatively simple:

a) Download binaries: the last ones I downloaded
b) I installed in $HOME/gnu-compilers
   % GNUINSTDIR=$HOME/gnu-compilers

   % cp gcc-4.10.tar.xz $GNUINSTDIR
   % cp gcc-4.8-infrastructure.tar.xz $GNUINSTDIR
   % tar -xvf gcc-4.10.tar.xz
   % cp gcc-4.8-infrastructure.tar.xz gcc-4.10
   % cd gcc-4.10
   % tar -xvf gcc-4.8-infrastructure.tar.xz

c) Set environment vars.
   % export PATH=$GNUINSTDIR/gcc-4.10/bin:$PATH

Take into account that gcc-4.8-infrastructure.tar.xz is necessary for GCC version 
4.8 and later, and it has to be unpacked in $GNUINSTDIR/gcc-4.10 according to the 
documentation in the web page. Step c) is needed for using the compiler, which is 
installed in steps a) and b).

2.- Install gfortran using source code

You should install from source code if either no binary form fits your platform/
environment or you want to contribute to or change the actual source code of the 
compiler/s, which is also referred to as
a) being a "Distributor" at
b) "for modifying GCC" at
As you may note, at this point there is almost no reference to gfortran (of gcc, by 
the way) at all, just GCC. 

The gfortran wiki refers to the web page "Download gfortran source code" at
(from the "Quick links" section at, "Download"...)

There are several options (well... basically, two options) from here, which I think 
would depend on what you want to do with GCC sources: a) "just" install, b) modify/
contribute. I'll make a subsection for each of them, since I think the step-by-step 
procedure would be different from the very first step, which is downloading the 

2.1) Install gfortran from source code: simple steps, not necessarily complete for 
     modifying and/or contributing to the GCC or gfortran in particular

Initially, there seems to be several pages where the installation from source code is 
a) A brief section, "Configuration and compiling", at
which refers to "compiler build instructions", at
b) A brief section, "Building from Source", at
which also refers to two different web pages, which also contain diferent data and/or 
incomplete and/or confusing:
c) "Installing GCC"

The most conceptually clear is the latter, which also has the text: 
     "The latest version of this document is always available at"
so it seems reasonable to start in this document, at least until something inconsistent 
or out of date appears, if any.

I initially agree in the description of the installation given in the document:
      The installation procedure itself is broken into five steps.
         1. Prerequisites
         2. Downloading the source
         3. Configuration
         4. Building
         5. Testing (optional)
         6. Final install 

However, from the point of view of step-by-step installation it could be simplified given 
that the own code takes care of some steps (maybe that slight change in the code was 
made after the document was written).

Steps 1. and 2. could be considered only one, divided in 2 substeps. Also, I will skip 
step 5 for two reasons: a) the documentation itself is biased to skip the optional step: 
" ... is broken into five steps.", and b) unless some compiling/linking errors appear, the 
GCC would be ready to be successfully used. The latter would be not the case for the 
next section, 2.2), which will be intended for those modifying sources. Furthermore, I'll 
use letters for the step-by-step section in order to avoid "extra-confusion"... with 
numbering in the original GCC install documentation.

STEP A: Download all the sources: GCC + GCC prerrequisites
     A.1: Download GCC sources
          From page, you end up in a long list of
          GCC packages, all starting with "gcc", look for the last version and download.
          I downloaded


          Side note: sources version for this install would be "one less" than the binary
          version you can download (as shown in the previous section). Actually, the 
          "current" source development version would be that of the last binary version
          you can download. Given that this subsection is not intended to change sources,
          I prefer to download the "current stable" source version instead of the "current
          development" source version. Side note on the side note: "current stable" and 
          "current development" versions are not expressions used in the GCC documentation.

     A.2: Download GCC prerequisites
          The "Prerequisites" explanation in the GCC documentation is complete as far as
          I've (not very thoroughly) checked. However, the GCC source .tar.gz includes code 
          to download the prerequired software packages most likely not available or not 
          available in the proper versions. I'll use it.

     A.3: Create the directories for building the compiler and to install the binaries
          The compiler should be built in a directory independent from the one in which the
          sources are. The directory in which the binaries will be installed can be 
          (automatically) created later, but I usually install in a <base_directory> (e.g.
          $HOME/gnu-comps) as

     Summary for downloading GCC sources, including GCC prerequisites (and a few dirs.):
          # base directory: src, obj (build), and install
          % GNUCOMPS=$HOME/gnu-compilers

          # version, there should be a .tar.gz or .bz2 or similar containing the src in 
          # $GNUCOMPS having this version number
          % GCCVERSION=4.9.0


          % cd $GNUCOMPS

          % mkdir $GNUOBJDIR
          % mkdir $GNUINSTDIR

          % tar -xvf gcc-$GCCVERSION.tar.gz

          % cd $GNUSRCDIR

          % ./contrib/download_prerequisites

          % cd ..
     Thus, the directory structure is
              <base_directory>/<src>  --> $HOME/gnu-compilers/gcc-$GCCVERSION
              <base_directory>/<obj>  --> $HOME/gnu-compilers/$GCCVERSION-objdir
              <base_directory>/<inst> --> $HOME/gnu-compilers/$GCCVERSION-instdir

     Sometimes, the computers are not directly connected to the Internet (e.g. those in
     production environments) so the script contrib/download_prerequisites will fail and 
     you should download the prerequired packages "by hand". It is not a hard work, 
     though, just follow the script contrib/download_prerequisites and you'll be ready 
     to compile and install from sources. In the specific case of the gcc-4.9.0.tar.gz, 
     the prerequired packages (those in contrib/download_prerequisites) for this GCC
     version are: 

STEP B: Configure the GCC
     Complete configuration details can be found at
     and, also, some information can be obtained issuing
        <base_directory>/<src>/configure -h 
     However, the information is not always the same (and I didn't check looking for 
     details). Having downloaded the sources as indicated in STEP A, several details 
     are already defined, i.e. it is not necessary to define many options at 
     configuration. More specifically: 
     are not necessary, since the five packages are found in the sources directory and,
     thus, automatically built. 

     The most useful configuration options I've found are:
          --prefix: where to put installation binaries
          --enable-languages: what specific compilers to build (including gfortran)
          --disable-multilib: avoid to build, for example, 64- and 32-bit binaries
                              in a 64-bit computer/environment.
     Thus, having defined the previous environment variables (those in STEP A), the 
     configuration step is "reduced to":
          % cd $GNUOBJDIR
          # Env. vars.
          % export PWDCMD=`which pwd`

          % $GNUSRCDIR/configure \
                     --prefix=$GNUINSTDIR \
                     --enable-languages=c,c++,fortran \
                     --disable-multilib \
                     > CONFIG.OUT 2>&1
     where the PWDCMD environment variable is set following the advice given in the 
     configuration page (, because many 
     times my $HOME dir. is mounted via NFS. 

STEP C: Build the GCC
     Complete building details can be found at
     Many "short" instructions indicate just issuing make. However, I've found several
     problems via environments variables which interfere in this particular step. More
     specifically, the environment variables should be those needed *only* by the 
     tools (compiler and linker, mostly) used/needed to build the GCC. Thus, my steps
     to build the GCC are (again, take into account the previously defined environment 
          # Just to avoid some trouble at make
          % cd $GNUOBJDIR
          % make
     Note 1: the variables listed in the previous unset command are not used by the 
             tools used to build the GCC in any of the platforms I've used. 
     Note 2: I use the -j make option when more than one core and/or processor is used.
     Note 3: I use the at command in order to avoid having a console with scrolling 
             text while the GCC is being built.

     In single processor computers I use:
          % at -f make now +2 minutes
     In a multiprocessor computer, dual quad-Xeon, I use
          % at -f make -j 6 now +2 minutes

     Build time is rather long:
        About 4 hours in a P4 @ 2.4 GHz
        About 3 hours in a Xeon E5405 @ 2.00 GHz (runing in a single core, just make)
        About 1 hour in a dual-Xeon E5405 @ 2.00 GHz (8 cores in total, using make -j 6)

STEP D: Final install and set environment variables
     Complete final installation details can be found at
     Just a few steps (again, take into account the previously defined environment 
          % cd $GNUOBJDIR
          % make install
          % cd $GNUOBJDIR
          # Set env. vars.
          % export PATH=$GNUINSTDIR:$PATH
          % export LD_LIBRARY_PATH=$GNUINSTDIR/<system_specific_lib>:$LD_LIBRARY_PATH
     where <system_specific_lib> could be:
          lib in a 32 bit environment
          lib64 in a 64 bit environment

2.2) Install gfortran from source code for modifying and/or contributing to the GCC 
     or gfortran in particular


Error Report /comments: ftinetti @ gmail . com (delete whitespaces), with subject "gfortran - GCC - install"