Installing and using the GNU Fortran (gfortran) compiler on Windows

Department of Aerospace Engineering

AEE305 Numerical Methods

Download and install MinGW gfortran packages

  1. Download the installer here (download will start shortly after you click the link)
  2. or here.
  3. Run the downloaded file.
  4. Click Install
  5. Mark down the “Installation Directory” in this window. With the following options selected, click “Continue”
  6. Wait for the download to finish and click Continue
  7. In the Manager window, mark the following 3 items for installation:

  1. Click Installation > Apply Changes
  2. Click Apply
  3. Wait for package downloads to finish, it may take a few minutes
  4. Make sure that there are no ERRORs in the “Details” frame before clicking Close
  5. The following items should be ticked at this point
  6. Close the “MinGW Installation Manager” window

Set the environment variables

  1. Click the Start button and type “environment” and run “Edit the system environment variables”
  2. Click “Environment Variables”
  3. Now we will edit the following two “Path” variables under “User variables for <username>” and “System variables” frames. For one of each, select “Path” and click “Edit…”
  4. Click “New” and add the following 2 paths to the list:


If you are using an old version of Windows, you may not see a table and instead you have to enter these paths separated by semicolons.


“C:\MinGW” is the directory where you have installed MinGW to. Check if this directory exists. If this directory does not exist, it means that you either

so you should redo the respective steps.

  1. Verify that the new entries are added to the list. Make sure that you did not accidentally delete or overwrite other existing variables. If something goes wrong, click “Cancel” and retry. If everything looks good, click “OK”.
  2. Do this for both of the “Path” variables under “User variables for <username>” and “System variables” frames in the “Environment Variables” window.
  3. Click “OK” in the “Environment Variables” window.
  4. Click “OK” in the “System Properties” window.

Test the installation

  1. Click the Start button and type “cmd”, then run “Command Prompt”
  2. In the terminal, execute the following command (type it and hit Enter):

    gfortran --version
  3. You should see the following message that prints the version of GNU Fortran
  4. If you fail to get the version message successfully or you get the following message:

    'gfortran' is not recognized as an internal or external command, operable program or batch file.

    it means that either the Path environment variables are not set correctly or there is a problem with your MinGW installation. Check the respective steps again.

Compiling and executing

In the AEE305 course, you will:

  1. write code
  2. compile
  3. execute
  4. get results

Here is a demonstration of what you will mostly do. You are strongly encouraged to try it before the homework assignments.

gfortran comes with various versions of Fortran compilers (77, 90 etc...). gfortran automatically decides which compiler version to use based on the extension of your code file, so you don't have to specify it. That is, your code is compiled using version 90 if your file name is my_code.f90, or version 77 if your file name is my_code.f. Make sure that you are using whatever version is given to you and do not change it.