Installing gfortran on Windows

Can anyone tell me how to mount gfortran on Ubuntu in Windows? I keep getting things like

Ign:1 Index of /ubuntu focal-updates/main amd64 binutils-common amd64 2.34-6ubuntu1.4
Err:1 Index of /ubuntu focal-updates/main amd64 binutils-common amd64 2.34-6ubuntu1.4
404 Not Found [IP: 91.189.92.23 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/b/binutils/binutils-common_2.34-6ubuntu1.4_amd64.deb 404 Not Found [IP: 91.189.92.23 80]

Thanks,

John.

That version of Ubuntu is “focal” (i.e., 20.04). Unless you have some extended support contract with Canonical for that version, it’s considered EOL’d (hence the 404 status code).

This Wikipedia table lists the support ranges depending on the version.

You can either install a still-supported Ubuntu version, or upgrade to the 22.04 LTS (which is still within the standard support range).

This web site might help.

I would echo @jmwalrus and encourage you to install a more recent version of Ubuntu. I think 22.04 gives you gcc 13 by default.

To get more recent ones you might have to use the test repository ppa which should allow you to instal gcc 15.

you first do.

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

I then do:

sudo apt install gcc-15 gfortran-15 g+±15

After installation you have to use the version number to access the compiler

gfortran-15 -c a.f90

There is a way to set gfortran-15 as the default so you just have to type gfortran but I advise against it because the kernel and system libraries depend on a particular version of gcc.

I prefer to use gFortran on windows without wsl.

You can download from:

https://winlibs.com/

Sorry - I am not comfortable with changing my unix system, which I use for other purposes.

John.

Sorry to have wasted your time.

By following the instructions in Installing GFortran — Fortran Programming Language I now have gfortran working.

John.

1 Like

Yes. Those instructions are correct for installing GNU Fortran (gfortran) in Ubuntu under WSL.

You can do the whole installation with:

sudo apt update
sudo apt install -y gfortran
gfortran --version

Then test it with a small Fortran program:

cat > hello.f90 <<'EOF'
program hello
  implicit none
  print *, "Hello from Fortran on WSL!"
end program hello
EOF

gfortran hello.f90 -o hello
./hello

You should see something similar to:

 Hello from Fortran on WSL!

For your Fortran 77 programs, gfortran can compile them too. For example:

gfortran program.f -o program
./program

For older fixed-form F77 source that uses legacy extensions, this is often useful:

gfortran -std=legacy program.f -o program

So you don’t need a separate Fortran 77 compiler—gfortran is suitable for both your .f legacy programs and modern .f90 programs.

I understand that, if the system is working, upgrading is a drastic measure. But…

If those other purposes you mentioned you use the system for, are security-sensitive, you might want to consider upgrading at some point (since the expectation is that an Ubuntu LTS only has 5 years of standard support).

(the AI craze sort of accelerated the “vulnerability-of-the-week” thing, and according to that Low Level guy on YouTube, the recent ones include malware on a VM that can escape the control of its hypervisor.)

Slimmer install

I am glad they were useful!

I always wonder if all the tutorials that we have on the page are actually helpful and used by people, but you are a proof that they were useful for at least one person. :slight_smile: