Install G77 on Ubuntu >= 9.04

It is possible that you still need to install g77 to compile a Fortran program on your latest version of Ubuntu, but it isn’t the repositories!! Don’t worry, it is easy.

THIS APPROACH DOES NOT WORK WITH THE LATEST VERSIONS OF UBUNTU. I HAVE CREATED AN UPDATED GUIDE HERE.

For this install we first need to add the Ubuntu 8.04 repo’s, do this by editing the sources.list file with your favourite text editor. I’ve used gedit here:

sudo gedit /etc/apt/sources.list

Then to the bottom of that file add:

deb http://hu.archive.ubuntu.com/ubuntu/ hardy universe
deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy universe
deb http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe

Then we need to run an update and install g77, do this with:

sudo apt-get update
sudo apt-get install g77

Now hopefully g77 will work, to test it try compiling a `Hello World!’ program. With a file name of something like `hello.f’ include the following lines:

       program hello
          print *, "Hello World!"
       end program hello

and then in a terminal window, navigate to the folder containing hello.f and run:

g77 -o hello hello.f

Then (if nothing has gone wrong) be able to run the program `hello’ with:

./hello

If you get error messages here then there could be an error with a link, I had such a problem with lgcc_s, to fix this just copy the file to the correct location!

sudo cp /usr/lib/gcc/x86_64-linux-gnu/4.6.3/libgcc_s.so /lib/libgcc_s.so.1

And everything should work fine. You then will want to disable the old repo’s by adding `##’ in front of each one, i.e. reopen sources.list:

sudo gedit /etc/apt/sources.list

and change the last lines to:

## deb http://hu.archive.ubuntu.com/ubuntu/ hardy universe
## deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy universe
## deb http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe
## deb-src http://hu.archive.ubuntu.com/ubuntu/ hardy-updates universe

Now compile away!

This entry was posted in Linux and tagged , , , . Bookmark the permalink.

4 Responses to Install G77 on Ubuntu >= 9.04

  1. Dushyant Kumar says:

    Hi,

    I tried to follow your instructions; but, it could not find g77 after “sudo apt-get update” ran fine.

    $ sudo apt-get install g77
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package g77 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

    Some help would be appreciated.

  2. Dushyant Kumar says:

    Hi Sean,

    I just got answer on stackoverflow. I just want to leave a link in case someone gets the same error:
    http://stackoverflow.com/questions/28068148/how-to-install-the-gnu-fortran-77-compiler-or-g77-on-ubuntu-14-04

    • Sean says:

      Thanks for your comment Dushyant. I’m not sure why it failed for you, I’ll look into it. In the mean time I’m glad you managed to get a working solution from stack overflow.

      Thanks 🙂

  3. Sean says:

    I have wrote a new version of this guide for the latest versions of Ubuntu here: http://seanelvidge.com/2017/01/install-g77-on-ubuntu-14-04/

Leave a Reply

Your email address will not be published.