Degenerate Conic

Algorithms • Modern Fortran Programming • Orbital Mechanics

Apr 26, 2025

Conda + Fortran

fortran-ai-2

The dark ages of confusion about where to get and how to install a Fortran compiler for your platform are over. In recent years, along with the overall renaissance of the Fortran ecosystem, with the conda package manager and the conda-forge package repository, we now have have easy access to all these free compilers for the three major platforms (Windows, Linux, and Mac):

Compiler Platform conda-forge Package Version
gfortran†† win-64 gfortran conda
gfortran†† linux-64 gfortran conda
gfortran†† osx-arm64 gfortran conda
flang‡ win-64 flang conda
flang‡ linux-64 flang conda
flang‡ osx-arm64 [Package not yet available] conda
ifx* win-64 ifx_win-64 conda
ifx* linux-64 ifx_linux-64 conda
lfortran† win-64 lfortran conda
lfortran† linux-64 lfortran conda
lfortran† osx-arm64 lfortran conda

Notes: †† gfortran is the venerable GNU Fortran compiler, the most mature open source Fortran compiler currently available. *ifx is Intel's replacement for ifort using an LLVM backend. It is free but not open source. They did not port it to the Mac ARM architecture, so that version of the compiler does not exist. On Windows, ifx still requires a Visual Studio installation to work. ‡flang (a.k.a. flang-new) is the official LLVM Fortran compiler. †LFortran, which also uses LLVM, is still under development and is currently an "alpha" product.

There is occasionally hand-wringing from some folks (e.g., SciPy, Los Alamos, etc.) that relying on Fortran compilers is somehow a risky proposition. But it has literally never been easier to install an up-to-date modern compiler for all platforms. Using conda, installing and trying out a Fortran compiler nowadays is as simple as this:

conda create --prefix ./env gfortran
conda activate ./env
gfortran --version

In addition, a lot of other tools that a Fortran programmer needs nowadays are also available via conda-forge. For example:

  • fpm -- Fortran Package Manager
  • ford -- Automatically generates Fortran documentation from comments within the code
  • fortls -- Fortran Language Server
  • fprettify -- Auto-formatter for modern fortran source code
  • findent -- Indent, relabel and convert Fortran sources

And you can also find other developer tools you may need including:

  • Python (and all the various Python libraries)
  • Cmake -- A Powerful Software Build System
  • Meson -- Open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible.
  • Ninja -- A small build system with a focus on speed.
  • git -- Distributed version control system

So, basically, you can get started with just one command:

conda create --channel conda-forge --prefix ./env gfortran fpm ford fortls fprettify findent cmake meson python git ninja

And it can all be installed in your user directory without requiring admin privileges on the machine (and if you want to remove it just delete that env folder and you are done). If you are using VSCode, you also will want to install the Modern Fortran extension. Then from the command palette, you can select "Python: Select Interpreter" and choose the env environment folder you created above. Then you are off to the races.

vscode-window

The conda distribution I recommend is miniforge. This is a version of conda that, by default, uses the conda-forge package channel rather than the commercial Anaconda channels which require a license to use. Note that conda itself is and has always been a free and open source project, so don't let your confused IT department get away with telling you it requires a paid license to use.

Another newer tool is pixi by the folks at prefix.dev. This is billed as a "fast software package manager built on top of the existing conda ecosystem". The syntax and some of the concepts are a little different, but it's an alternative way to install and use conda packages, and also works great.

See also