Fortran
  • Learn
  • Compilers
  • Community
  • Packages
  • News
  • Discourse
  • Twitter
  • Github
  • RSS Feed
Back to Learn Fortran index

Setting up your OS

  • Introduction
  • Choosing a compiler
  • Installing GFortran
    • Text Editors
    • IDEs
    • Smart Tips

    Installing GFortran

    GFortran is the name of the GNU Fortran project. The main wiki page offers many helpful links about GFortran, as well as Fortran in general. In this guide, the installation process for GFortran on Windows, Linux, and macOS is presented in a beginner-friendly format based on the information from GFortranBinaries.

    Windows

    Three sources provide quick and easy way to install GFortran compiler on Windows:

    1. http://www.equation.com, provides 32 and 64-bit x86 executables of the latest (10.2) gcc-version.
    2. TDM GCC, provides 32 and 64-bit x86 executables of the 9.2 gcc-version.
    3. MinGW-w64 provides a 64-bit x86 executable of the 8.1.0 gcc-version.

    In all the above choices, the process is straightforward—just download the installer and follow the installation wizard.

    Unix-like development on Windows

    For those familiar with a unix-like development environment, several emulation options are available on Windows each of which provide packages for gfortran:

    • Cygwin: A runtime environment that provides POSIX compatibility to Windows;
    • MSYS2: A collection of Unix-like development tools, based on modern Cygwin and MinGW-w64;
    • Windows Subsystem for Linux (WSL): An official compatibility layer for running Linux binary executables on Windows.

    All of the above approaches provide access to common shells such as bash and development tools including GNU coreutils, Make, CMake, autotools, git, grep, sed, awk, ssh, etc.

    We recommend the WSL environment for those looking for a Unix-like development environment on Windows.

    Linux

    Debian-based (Debian, Ubuntu, Mint, etc…)

    Check whether you have gfortran already installed

    which gfortran
    

    If nothing is returned then gfortran is not installed. To install gfortran type:

    sudo apt-get install gfortran
    

    to check what version was installed type:

    gfortran --version
    

    You can install multiple versions up to version 9 by typing the version number immediately after “gfortran”, e.g.:

    sudo apt-get install gfortran-7 
    

    To install the latest version 10 you need first to add / update the following repository and then install:

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

    Finally, you can switch between different versions or set the default one with the update-alternatives (see manpage). There are many online tutorials on how to use this feature. A well structured one using as an example C and C++ can be found here, you can apply the same logic by replacing either gcc or g++ with gfortran.

    RPM-based (Red Hat Linux, CentOS, Fedora, openSuse, Mandrake Linux)

    sudo yum install gcc-gfortran
    

    Since Fedora 22, dnf is the default package manager for Fedora:

    sudo dnf install gcc-gfortran
    

    Arch-based (Arch Linux, Antergos, Manjaro, etc…)

    sudo pacman -S gcc-fortran
    

    macOS

    Xcode

    If you have Xcode installed, open a terminal window and type:

    xcode-select --install
    

    Binaries

    Go to fxcoudert/gfortran-for-macOS to directly install binaries.

    Homebrew

    brew install gcc
    

    Fink

    GNU-gcc Package link

    MacPorts

    Search for available gcc versions:

    port search gcc
    

    Install a gcc version:

    sudo port install gcc10
    

    OpenCoarrays

    OpenCoarrays is an open-source software project that produces an application binary interface (ABI) used by the GNU Compiler Collection (GCC) Fortran front-end to build executable programs that leverage the parallel programming features of Fortran 2018. Since OpenCoarrays is not a separate compiler, we include it here, under gfortran.

    While with gfortran you can compile perfectly valid code using coarrays, the generated binaries will only run in a single image (image is a Fortran term for a parallel process), that is, in serial mode. OpenCoarrays allows running code in parallel on shared- and distributed-memory machines, similar to MPI:

    cafrun -n <number_of_images> <executable_name>
    

    The process of installation is provided in a clear and comprehensive manner on the official site.

    We emphasize that native installation on Windows is not possible. It is only possible through WSL.

    Back

    Next

    Learn · Compilers · Community · Packages · News
    This site's source is hosted on GitHub.