Installation of GFortran in Windows 10

Yutaka Masuda

February 2020

Back to index.html.

Installation of GFortran in Windows 10

This article explains how to install GFortran in Windows 10. GFortran is a free Fortran compiler. The users can use it with no charge. GFortran is a product of an “open source” project to develop a collection of free compilers (GCC).

The compiler is the most useful when combining with other commands of Linux/Unix. Because Windows does not have the commands by default, programmers developed some packages to have the commands in Windows. Msys2 is one of them, and it includes the free compilers, and GFortran developers recommend it for Windows users.

Here is a procedure for the installation of Msys2 as of January 2020.

Msys2 and Mingw-w64

Installation

Step 1: Visit the official GFortran Wiki to find the link to Msys2 website. It shows a link to Mingw-w64, the name of the project that develops MSYS2. Go to the Mingw-w64 web page.

GFortran Wiki

Step 2: Visit the Mingw-w64 project site, and you find the “Download” link. Go to “Download”.

Mingw-w64 project website

Step 3: This page shows all the packages that this project maintains. Choose Msys2.

Msys2 link

Step 4: The page shows a link to Msys2 website in Github. Go to the website.

Link to Msys2 project website

Step 5: Get Msys2 installer on this website. Download a file with msys2-x86_64-xxxxxxxx.exe (xxxxxxxx is replaced with the date which is released). If you know your system is 32bit, download msys2-i686-xxxxxxxx.exe.

Msys2 installer website

Step 6: Run the installer and follow the instruction to set up the program.

Msys2 installer

Step 7: Invoke Msys2 window. The program runs automatically for the first time. After that, you can run it from the menu. Choose MSYS2 MinGW 64-bit (32-bit if needed).

Msys2 in the menu

Step 8: Make sure that you see a Msys window.

Msys2 window

Step 9: Msys2 consists of many dependent programs. Each program is prepared as a package. If the package is modified, you can download it through the internet. This process is automated by a command pacman.

For the first time, you have to date the built-in packages through the internet. In the Msys2 windows, type the following command.

pacman -Syu

It will ask you whether you allow downloading the updated packages. You can type y for yes. If it fails, close the window and try again.

Step 10: GFortran is also provided as a package. Type the following command in the window to install GFortran.

pacman -Su gcc-fortran

As above, it will ask you if you want to install the package. Type y, and wait for a while to finish the installation. After this step, you can use GFortran in this window.

You can confirm the successful installation with the following command.

gfortran

Directory structure

The Msys2 window runs Bash, and you can use most Linux commands in the window. Also, when you create some files, you can access the files with Windows Explorer.

The home directory is somewhere on your computer. You can access the drive C, use /c/. For example, the real home directory in Windows is /c/Users/your_name if your account name is your_name. Using this rule, you can change the directory to Documents, type cd /c/Users/your_name/Documents.

Back to index.html.