0

My code runs fine with the command

   gfortran-11 Hello.f90 -o Hello

but if I check the version of the gfortran, it shows 9.3.0 on Ubuntu 20.04.

So my concern is how to make it default or do I have to type gfortran-11 every time I use it?

Robert12
  • 7
  • 5

2 Answers2

1

This is really a system administration question. Since it tangentially deals with a compiler, it might be on-topic.

There are various ways how concurrent versions are treated in various operating systems. If you use Linux, you can use

alias gfortran=gfortran-11

You can put this into your ~/.bashrc or some equivalent, if you use one (e.g., the ~/.bash_aliases file - see https://askubuntu.com/questions/1414/how-to-create-a-permanent-alias).


For tools like Make you can normally set

export FC=gfortran-11

or

FC=gfortran-11 ./make

or some other variable name that your Makefile happens to use. I use this routinely with SCons.


Another good option is the update-alternatives system. See https://askubuntu.com/questions/26498/how-to-choose-the-default-gcc-and-g-version

If you configure (install) the appropriate options according to the instructions (change g++ to gfortran), you will be able to switch between the versions using

 sudo update-alternatives --config gfortran
1

One way to solve this is to create a symlink to gfortran-11 called gfortran, and to add this symlink to your PATH with higher priority than the original gfortran.

This could be acheived by e.g. running

mkdir ~/.bin
ln -s [path_to_gfortran-11] ~/.bin/gfortran

and then adding

export PATH=~/.bin:$PATH

to your .bashrc or equivalent.

veryreverie
  • 2,871
  • 2
  • 13
  • 26
  • Your answer sounds similar to this link which i have previously followed but could not understand the last step like you said about exporting to .bashrc. https://camb.readthedocs.io/en/latest/fortran_compilers.html#:~:text=Check%20the%20version%20using%20%E2%80%9Cgfortran%20%E2%80%93version%E2%80%9D.&text=To%20install%20from%20the%20standard,sudo%20apt%2Dget%20install%20gfortran%E2%80%9D – Robert12 Feb 04 '22 at 10:31
  • So my home directory has this folder gfortran-symlinks. So which command i should put in the terminal for exporting to .bashrc? – Robert12 Feb 04 '22 at 10:34
  • 2
    Just use any text editor and put the export command into the `.bashrc` file. You could use echo, but I suggest just doing it manually, it is safer for you. – Vladimir F Героям слава Feb 04 '22 at 10:48