Install NAG Fortran compiler

The NAG Fortran compiler is a non-free compiler for modern Fortran. New features in NAG 7.0 vs. NAG 6.2 include:

  • Fortran 2008 coarray for multiple images
  • half-precision (float16)
  • Fortran 2008 submodule support
  • -f2018 flag to indicate Fortran 2018 standard semantics

If you don’t already have a NAG license, request a NAG trial. Typically they ask for a little info to help them understand their potential customer’s needs.

Download NAG compiler and extract the compressed folder to a non-ExFAT / non-FAT32 drive, since symbolic links are used.

Run installer:


Consider installing to /home/username/.local/bin and all other choices as default. DO NOT use ~ or $HOME as the NAG installer did not recognize these shortcuts!

The NAG compiler should be available:


However, compilation is disabled until a license is installed.

License setup

This procedure is for Linux. License key comes in an email from NAG. Scroll down for the one-line license key and copy it to $HOME/.local/lib/NAG_Fortran/nag.key

Add to ~/.bashrc:

export NAG_KUSARI_FILE=$HOME/.local/lib/NAG_Fortran/nag.key

Open a new Terminal and nagfor should now be able to compile programs.

NAG license FAQ

The graphical debugger in NAG Fortran Builder is for Windows and MacOS only. For NAG command-line debugging use dbx90. CMake and Meson support NAG Fortran compiler.

Related: Five free Fortran compiler suites