The gfortran is a compiler of the GNU Compiler Collection (GCC). The gfortran compiler is used for compiling programs that is written in Fortran programming language.
This tutorial shows how to install gfortran 11 on Ubuntu 20.04.
Install gfortran
Add the Toolchain repository by using the following command:
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
Install gfortran 11 with command:
sudo apt install -y gfortran-11
Now verify that the installation completed successfully by checking gfortran version:
gfortran-11 --version
Testing gfortran
Create a main.f90
file:
nano main.f90
Once file was opened, add the code:
program test
print '(a)', 'Hello world'
end program test
Run the following command to compile a code:
gfortran-11 main.f90 -o test
Run a program:
./test
Uninstall gfortran
If you wish to completely remove gfortran and related dependencies, execute the following command:
sudo apt purge --autoremove -y gfortran-11
Remove GPG key and repository:
sudo rm -rf /etc/apt/trusted.gpg.d/ubuntu-toolchain-r_ubuntu_test.gpg
sudo rm -rf /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-focal.list
Leave a Comment
Cancel reply