Install latest GFortran on Linux

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. On Ubuntu, first install the distro-packaged compiler:

apt update
apt install gfortran

If you need a newer GCC / GFortran than your Ubuntu release provides, try:

add-apt-repository universe

The Ubuntu toolchain test PPA is often the simplest way to get a newer GCC / GFortran on Ubuntu: Ubuntu Toolchain Test PPA

Add the PPA by:

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

apt update

Install the desired compiler version, for example:

apt install gfortran-15

Then select the compiler version you want to use. Switch between compiler versions with update-alternatives.


Related:

  • Windows: Install latest Gfortran
  • macOS: get latest gfortran by brew install gcc