Home > Mobile >  Making gfortran version 11 as default
Making gfortran version 11 as default

Time:02-04

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?

CodePudding user response:

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.

CodePudding user response:

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
  •  Tags:  
  • Related