Gfortran is a free and open source Fortran compiler that is part of the GNU Compiler Collection (GCC). Fortran is a programming language that is widely used for scientific and numerical computing. If you want to use Fortran on your Mac, you need to download and install Gfortran first.
In this article, I will show you how to download and install Gfortran for Mac, using two different methods: a standalone installer and a package manager. I will also show you how to test your installation and run a simple Fortran program.
Method 1: Download and Install Gfortran for Mac using a Standalone Installer
A standalone installer is a file that contains everything you need to install Gfortran on your Mac. You just need to download it, run it, and follow the instructions. This is the easiest and most convenient method, especially if you don't have any other GCC compilers installed on your Mac.
To download and install Gfortran for Mac using a standalone installer, follow these steps:
Go to https://github.com/fxcoudert/gfortran-for-macOS/releases, which is the official repository of Gfortran packages for macOS.
Find the latest release that matches your macOS version and processor type. For example, if you have macOS Monterey (macOS 12) and an Apple Silicon computer, you should download the file gfortran-ARM-12.2-Ventura.dmg. If you have an Intel-based computer, you should download the file gfortran-Intel-12.2-Ventura.dmg.
Click on the file name to download it to your Mac.
Double-click on the downloaded file to open it. You will see a window with a gfortran icon and an Applications folder icon.
Drag and drop the gfortran icon onto the Applications folder icon. This will copy the GCC compilers (including gfortran) to /usr/local/gfortran on your Mac.
Close the window and eject the disk image file.
Congratulations! You have successfully installed Gfortran for Mac using a standalone installer.
Method 2: Download and Install Gfortran for Mac using a Package Manager
A package manager is a tool that allows you to install, update, and manage software packages on your Mac. You can use a package manager to download and install Gfortran for Mac, along with other GCC compilers and dependencies. This method is more flexible and customizable, but also more complex and requires some command-line skills.
To download and install Gfortran for Mac using a package manager, follow these steps:
Install a package manager on your Mac, if you don't have one already. There are several package managers available for macOS, such as Homebrew, MacPorts, or Fink. In this article, I will use Homebrew as an example. To install Homebrew, open a Terminal window and type: