Install latest GFortran 9 on Linux

Gfortran 9 improves support for Fortran 2018 features. Newer version of compilers generally have more useful and detailed warning messages. As with any compiler, newer versions of Gfortran may require rebuilding other libraries linked with the Fortran compiler if the ABI presented by libgfortran changes. On Linux, one can switch Gfortran versions with update-alternatives. If experiencing errors getting any version of gfortran installed in Ubuntu, try:

add-apt-repository universe

Two popular methods of installing the latest GFortran compiler on Linux are:

  • Ubuntu PPA
  • Homebrew

Ubuntu PPA

The latest GCC / Gfortran for Ubuntu is available from the Ubuntu-test PPA. Add Ubuntu-test PPA by:

add-apt-repository ppa:ubuntu-toolchain-r/test

apt update

Install the most recent Gfortran (similarly for gcc-9, g++-9) by:

apt install gfortran-9

Switch between compiler versions with update-alternatives.

Homebrew

Linux, MacOS and Windows Subsystem for Linux can install the latest GFortran via Homebrew:

brew install gcc