Installing latest gfortran

Currently the gfortran compiler in my ubuntu system is

GNU Fortran (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

Wishing to update it I did what Installing GFortran - Fortran Programming Language
says:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gfortran-10
but on doing that I find

john@johns-laptop:~$ gfortran --version
GNU Fortran (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

What must I do now?

2 Likes

see this

It describes the use of the update-alternatives command to get what you are after.

Just switch to Fedora Linux, which always ships with the latest GFortran.

1 Like

If you are using the bash shell you could add

alias gfortran=gfortran-10

to the .bashrc file in your home directory.

Another solution is to build from source Installing GCC - GNU Project , I had to resort to that to test some features from the latest release.

The general process should look something like this

  1. Clone gcc, git clone git://gcc.gnu.org/git/gcc.git gcc-src
  2. Checkout the release you want cd gcc-src && git switch releases/gcc-12.1.0
  3. Install dependencies ./contrib/download_prerequisites
  4. Configure Installing GCC: Configuration - GNU Project
  5. Build and install, make all -j8 && make install
1 Like

Thank you. Beliavsky’s solution was the easiest to use and it worked.