Install gfortran on FreeBSD
| Update pkg | |
| Install lang gcc | |
| Verify with gfortran --version | |
| Ports alternative |
Update pkg
Start with a refresh of the package catalog so pkg sees the latest package lists.
Run the update before every fresh install on a system that has not been updated for a while.
sudo pkg update
Install lang gcc
Gfortran ships with gcc on FreeBSD, so the lang port gives you both the C and the Fortran compilers.
sudo pkg install lang/gcc
Accept the install prompt when asked. The package pulls in the matching compiler libraries automatically.
Verify with gfortran --version
Ask the compiler for its version number right after the install. The binary may carry a version suffix on some systems.
gfortran --version
GNU Fortran 13.2.0
If the plain name is not found, try the suffixed name for your gcc release and use the name that answers.
Ports alternative
The Ports collection builds the same compiler from source instead of installing a ready package.
Stay with pkg while learning. Switch to Ports only when you need custom build options that the binary package does not offer.
Next: Fortran in Docker
Article author: Arthur Isaev