8

When I try to install libgfortran.so.3 on Ubuntu 20.04 using:

sudo apt-get install libgfortran3  

it shows:

E: Unable to locate package libgfortran3

How can I install Fortran on 20.04?

Matt Messersmith
  • 12,939
  • 6
  • 51
  • 52

3 Answers3

9

The problem here is that 20.04 doesn't support g++-6. To get around this you need a multi-step process:

  1. Put a temporary repository into /etc/apt/sources.list. For me that was deb http://gb.archive.ubuntu.com/ubuntu/ bionic main universe

  2. Now you can install gcc version 6 sudo apt-get install g++-6

  3. Make that the default version sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 6

  4. Now install gfortran sudo apt-get install libgfortran3

  5. Make sure it works strings /usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0 | grep GFORTRAN*

Edmund Walsh
  • 91
  • 1
  • 6
  • 1
    Thanks a lot for your input. Nevertheless I have the impression you could add also `apt-get update` somewhere between step 1 and 2. This will help a lot of new comers :-) – Ashkan Kamyab Jun 16 '21 at 22:51
  • Thanks Edmund, it helped me a lot, and I just find step 3 is not necessary. :) – 12tall Apr 08 '22 at 08:41
  • Getting error at step 2: `sudo apt-get install g++-6` Package g++-6 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'g++-6' has no installation candidate – Krishnaap Sep 11 '22 at 20:54
1

To install libgfortran libraries in Ubuntu 20.04:

  1. First install gcc version 6
  2. Then install libgfrotran3

Use this link to download the files. Click here

-1

libgfortran3 is not supported any more in Ubuntu 20.04 as it depends on an older version of gcc, which is no longer maintained in this version of the distribution. You can install a later version of libgfortran using:

sudo apt-get install libgfortran5
  • 2
    I fear it may not satisfy the dependencies of the OP's software. Major versions of libgfortran are not backwards compatible. We had several similar questions before, like https://stackoverflow.com/questions/44658867/r-v3-4-0-2-unable-to-find-libgfortran-so-3-on-arch?noredirect=1&lq=1 In general, it is possible to have severalversions of GCC in one computer and it is possible to install an old GCC by compiling from source or by getting a binary somewhere. – Vladimir F Героям слава Aug 06 '20 at 12:29
  • @VladimirF I am having a similar problem. My program needs libgfortran3 but after trying everything I can not find a way to install it. Can you tell me how to install gcc6 in ubuntu 20.04? Many thanks! – Joana Carvalho Sep 29 '20 at 17:15
  • 1
    @JoanaCarvalho Just download the source code and compile it. Follow the documentation https://gcc.gnu.org/wiki/InstallingGCC and https://gcc.gnu.org/install/index.html If you have any specific problems, open a question on this site. – Vladimir F Героям слава Sep 29 '20 at 17:24