Install gfortran
| Install on Linux | |
| gfortran --version | |
| First flags | |
| Compile and run |
Install on Linux
On most Linux distributions gfortran is one package install away from the standard repositories.
Update the package index first, then install the compiler package.
sudo apt update
sudo apt install gfortran
Other distributions use other package managers, but the package name stays gfortran or gcc-fortran in almost every case.
gfortran --version
After the install, confirm that the compiler answers from the command line.
gfortran --version
GNU Fortran 13.2.0
Any recent version is fine for this course. Version 9 and newer support everything used in the first lessons.
First flags
Three flags cover most beginner needs: warnings, the language standard, and optimization.
Start every compile line with -Wall -Wextra -std=f2018 so the compiler warns about suspicious code and checks the modern standard.
gfortran -Wall -Wextra -std=f2018 hello.f90 -o hello
Add -O2 when the program grows and speed matters. Leave it out while learning if error messages feel too long.
Compile and run
Save the hello program from the previous lesson as hello.f90, compile it to a binary named hello, then run the binary.
gfortran hello.f90 -o hello
./hello
Hello, Fortran
If the file name and the program name differ, nothing bad happens. The -o name only sets the name of the created binary.
Next: Your first program
Article author: Arthur Isaev