Fortran is a general-purpose, high-level programming language that is used especially for numeric and scientific computing. It was developed by IBM in the 1950s for high-performance computing and engineering applications.
Fortran has various versions the most recent is Coarray Fortran(2008/20018) with parallel computing capabilities. GNU Fortran or GFortran is an open-source Fortran compiler that is a part of the GNU Compiler Collection. It supports Fortran 95, Fortran 2003, and 2008 Standards. It is the basis for many other programming languages such as BASIC.
In this article, I will discuss how to install GNU Fortran in Ubuntu.
Prerequisites
You should have access to a user account on a Ubuntu system with sudo privileges.
Installing GNU Fortran in Ubuntu
Follow the given steps to install GNU Fortran on your Ubuntu system.
We will install the latest version of GFortran from its official PPA repository. Use the following command to add the repository to your system.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
Next, update your system’s package index by using –
sudo apt update
Now install the latest version i.e. GFortran 10 on your system –
sudo apt install gfortran-10 -y
Once the installation is completed you can verify it by executing the following command.
gfortran-10 --version
Run your first program in Fortran
Use a text editor and create a file with .f90
extension, add the given code in this file.
!Hello World program in Fortran
program hello
print *, 'Hello, World'
end program hello
Save this file and exit from the editor. Here I saved this program with the name hello.f90
.
Use the following command to compile this program –
gfortran hello.f90 -o hello
Now run it by using the given command –
./hello
This will display output as you can see in the image below.
For more information, you can read Fortran quick start tutorials.
Conclusion
You have successfully set up GNU Fortran on your Ubuntu system. If you have a query then write us in the comments below.