Gfortran upgrade

Hi everyone,

I am writing to seek your assistance regarding an issue I encountered with Gfortran. I am using Ubuntu 22.04.3 LTS, with the GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 is 11. I need to updated to Gfortran v13 to compile CNS. Therefore, I run the command below

     sudo add-apt-repository ppa:ubuntu-toolchain-r/test
     sudo apt update
     sudo apt install gfortran-13

I got the following at the end

    Processing triggers for man-db (2.10.2-1) ...
    Processing triggers for libc-bin (2.35-0ubuntu3.8) ...
    /sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

Then I run

      gfortran --version

but I see that I still have gfortran-11 installed.

Please does anyone know how to upgrade gfortran-11 to gfortran-13?
Also how can I remove Gfortran -11 from my system?
My operating system is: intel-x86_64bit-linux
I am using bash shell

Thank you

Try gfortran-13 --version

Yes, in Ubuntu gfortran is a link to the default gfortran version of your distribution.

For example, in Ubuntu 24.04:

$ ls -o /usr/bin/gfortran*
lrwxrwxrwx 1 root 11 janv. 31  2024 /usr/bin/gfortran -> gfortran-13
lrwxrwxrwx 1 root 28 mars  31 03:01 /usr/bin/gfortran-10 -> x86_64-linux-gnu-gfortran-10
lrwxrwxrwx 1 root 28 avril 12 10:32 /usr/bin/gfortran-11 -> x86_64-linux-gnu-gfortran-11
lrwxrwxrwx 1 root 28 avril  3 14:27 /usr/bin/gfortran-12 -> x86_64-linux-gnu-gfortran-12
lrwxrwxrwx 1 root 28 avril 14 09:31 /usr/bin/gfortran-13 -> x86_64-linux-gnu-gfortran-13
lrwxrwxrwx 1 root 27 mars  31 03:03 /usr/bin/gfortran-9 -> x86_64-linux-gnu-gfortran-9

The other versions must be called with their major version: gfortran-??

It is generally useful to have several versions installed. Your program may sometimes run faster with an older version. And older versions are more debugged (higher minor version). For example I have the 13.2, 12.3, 11.4 and 10.5.

Hi

Thank you very much for replying. Please I have further questions

How can I set the Gfortran-13 as default?

When I tried to compile CNS by command below

   make install compiler=gfortran

I got too many errors. Then after install gfortran-13, I run the command

   make install compiler=gfortran-13

But I got

  Installation directory: /home/sura/software/cns_solve_1.3/intel-x86_64bit-linux

  copying files in instlib directory intel-x86_64bit-linux to intel-x86_64bit-linux

  0read.me

  Makefile.header.1.ifort

  Makefile.header.2.gfortran

  Makefile.header.3.ifort_mp

  Makefile.header.4.pgf95

  Makefile.header.5.ifort_mp_profile

  Makefile.header.6.ifort_mp_tcheck

  Makefile.header.7.gfortran_mp

  arch_env

  machine_c.c

  machine_f.f

  >>>> Error: Makefile template for compiler gfortran-13 is not available

 make: *** [Makefile:38: install] Error 1

Please could you help me to resolve this issues?
What am I doing wrong?

Thank you

Nothing per-se. The software you are trying to install expects the compiler to be named gfortran, otherwise the provided build system doesn’t work.

You could try to create a copy of the Makefile templates and rename them to have gfortran-13 at the end. Actually this is what the CNS authors recommend: CNS Installation — haddock3 3.0.0 documentation

Makefile headers for each supported system-compiler combination are provided in instlib/machine/supported/ (for unsupported systems, see instlib/machine/unsupported/). If you already tried make install, the appropriate directory for your system (eg. mac-intel-darwin) will have been copied to the main cns_solve_1.3 directory. If this directory does not contain the desired file (eg. Makefile.header.2.gfortran), you can create one manually.

For example, for gfortran, create a new file named Makefile.header.6.gfortran inside the directory containing Makefile headers for your system. […continued…]

Another solution is to use an alias:

alias gcc='gcc-13'
alias gfortran='gfortran-13'

This alias would work during the execution of the current shell. You can also set this in your bashrc such that every time you open a shell it would automatically create the alias and always point to this version. I have created a small function in my bashrc in order to switch between different version of gnu or sourcing different versions of intel compilers as well.

That is useful shortcut, especially for a piece of software which only needs to be built once.

On Linux there is also the update-alternatives tool. I’ve used it a few times, but it is a bit involved to setup, and if you don’t use it often, you forgot how to switch between alternatives. This blog post explains its use.

Thank you so much for prompt reply. I will try ivanpribec solution which is the CNS authors recommend. Does a number “6 “in the command Makefile.header.6.gfortran is a way to name the new file and it does not represent any version or resources.

I appreciate your help very much.

Thanks

A solution is to modify the symbolic link. For example, here I replace gfortran-13 (default in my distribution) by gfortran-10:

$ ls -o /usr/bin/gfortran
lrwxrwxrwx 1 root 20 août  25 12:18 /usr/bin/gfortran -> /usr/bin/gfortran-13
$ sudo ln -s -f /usr/bin/gfortran-10 /usr/bin/gfortran
$ gfortran --version
GNU Fortran (Ubuntu 10.5.0-4ubuntu2) 10.5.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ls -o /usr/bin/gfortran
lrwxrwxrwx 1 root 20 août  25 12:17 /usr/bin/gfortran -> /usr/bin/gfortran-10

You need the -f option (--force) of the ln command because the link already exists.

Note that I don’t know what will happen to that link if an upgrade of your system modifies the gfortran files.