Download Gfortran Mac

Apr 27, 2012 This is how I installed gfortran on my Mac: Visit, and select a binary distribution for your version of Mac OS X, e.g. Gfortran-snwleo-intel-bin.tar.gz for Snow Leopard. Download the file and open the download directory in Terminal. To install gfortran do the following. I am having a problem with command tools, i am using mac 10.8, downloaded the command tool, install it.The installation goes step by step as described. But when installation finish, it treats the software as an external drive, or doesn’t install it in “machintosh HD” as it is supposed to. That gfortran target (darwin10) is for Snow Leopard. I don't have that gfortran; the Xcode I have (4.5) only came with OSX SDKs 10.7 and 10.8 (Lion and Mountain Lion). The compiler that came with Xcode was built for Lion - the target (from gcc -v) is i686-apple-darwin11. I do have the command line tools installed btw (as also described in the. NOTE: The codeblocks-20.03mingw-setup.exe file includes additionally the GCC/G/GFortran compiler and GDB debugger from MinGW-W64 project (version 8.1.0, 32/64 bit, SEH). NOTE: The codeblocks-20.03(mingw) files are provided for convenience to users that are allergic against installers. However, it will not allow to select plugins.

Installing and using gfortran Fortran on a Mac.

So if you're in MATH 190 and you're having a hard time with installing fortran95 or any of the other suggested compilers,don't worry, there is a solution! On every Mac computer, there is a application called terminal that allows you tocommunicate with the computer and get stuff done.

So first things first, you need to be connected to the internet. Open Terminal, and type the following command
'sudo apt-get install gfortran'

Terminal will then ask a password, enter it and allow the program to install on your computer. This is your compiler;it's called gfortran! If this command doesn't work for some reason, just go to Google search 'gfortran' and you shouldeasily find a link to download it from.


It doesn't have a fancy user interface like SciTE, however it gets the job done. Now that gfortran is installed on yourmachine, you can get to work. But you must learn how to use a text editior first.

The textedit, however appropriately named is pretty useless for witing programs because it insists on saving files as .rtf, which can't be compiled by gfortran.

All Macs come with a few editors, namely: VIM, nano and emacs. To use them, open up terminal again, and type any of the following

This will open up the text editor inside terminal, where you will code and compile. I find that vim is really easy and effective to use.Most professionals prefer emacs, and nano is very easy, but sometimes too simply made. However, try out all three (look on Google fortutorials on how to use these editors).

Download Gfortran Mac

Now that you have a compiler and and editor, you have everything you need to write your programs for this class! So, let's write aneasy 'Hello World' program in f95.

In your editor, type the following.

program test
print *, 'Hello World!!'

Save this program as hello_world.f95. Now the cool part; we're going to use terminal to compile this code. The following command shouldbe committed to memory. To compile the code type (without the quotes)

'f95 -o test.exe hello_world.f95'

Let's break this command down. The first part addressed the compiler you wish to use, in this case f95 (which comes with gfortran).If you coding in C++ you would put g++ or something instead of f95. The next part '-o' tells f95 to do something. In this case, we're telling f95 to make test.exe out of hello_world.f95. Note, the name of the executable file is irrelevant. I could've named itelephant.exe or hello_world.exe o whatever, you get it.

To recap, address the compiler, command it to do something (with -o), in this case 'test.exe hello_world .f95', we're telling it tomake an executable called test.exe out of hello_world.f95

If you type this correctly, a new line in terminal should appear. This means your code compiled just fine and the .exe file was made.Now you want to run the file! The final command you need to learn is the following (again without the quotes),


This simply means, 'Run the executable file, test.exe'. Press enter after typing the command, and the program should run!

Good luck!!
Neill Warrington

gfortran for Mac

DISCLAIMER: I provide this information here to aid my memory and in thehope that others will find it a useful resource based on my experiences of installing a gfortran compiler on Macs. I am not a computer scientist orFortran guru and, as such, am unlikely to be able to help you with Fortran code,compilation or runtime problems.

There are several options available for installing gfortran for Mac OS X,other than installing from source code.

Download Gfortran Mac

GCC Wiki

I currently choose to use the relevant gfortran installer (.dmg) packagesprovided through the GCC Wiki (opens in new window). Note that the files areinstalled in /usr/local system directories which require the administratorpassword.

Download Gfortran Macports


There are also various tar-files of gfortran distributions provided at the High PerformanceComputing web page. There are up-to-date distributions for some systems(only Mac OS X 10.7 (Lion), 10.8 (Mountain Lion), 10.9 (Mavericks) and 10.10(Yosemite) as of the last update of this page).

I recommend not to choose a package containing a version that is not a stable version accordingto the main GCC web site. Furthermore, for simplicity, I would recommendonly to install the relevant 'gfortran only' distributions.

The files are gzip'd tar-files which should be unpacked, for instance byusing the Terminal application, as follows:

sudo tar xvfz[tar-file] -C /

Note that the files are installed in /usr/local system directories whichrequire the administrator password.

The R Project

Previously, I had preferred to use the gfortran packages distributed inassociation with the R Project. These can be found in the 'Apple Xcode gcc-42add-ons' section of their Tools web page (opens in new window) or via the direct linksbelow. These gfortran packages and updates are specifically built to matchApple's own gcc builds. This does mean that the version is back at GCC 4.2,which is undoubtedly where it will stay since GCC changed their licensing andApple has stopped updating their GCC distribution with Xcode. Nonetheless, myexperience shows that this distribution is one that always works.

There are several packages relevant to particular Mac OS X and Xcodeinstallations. Run gcc-v to find out which Apple gcc build is currently installed as part of theXcode tools.

  • Mac OS X 10.7 (Lion) and 10.8 (Mountain Lion):

    One may need to apply a link after installing one of these packages so 'gfortran' may be used as a command, e.g.

    sudo ln -s /usr/bin/gfortran-4.2 /usr/bin/gfortran

    Otherwise, simply use the explicit command 'gfortran-4.2'.

  • Mac OS X 10.6 (Snow Leopard):
  • Mac OS X 10.5 (Leopard):

The files for builds 5564 and 5566 are gzip'd tar-files which should beunpacked, for instance by using the Terminal application, as follows:

sudo tar xvfz[tar-file] -C /

Note that the files are installed in /usr system directories which requirethe administrator password.

Packages for older OS X and Xcode versions are also available on the pagelinked to above.

Compatibility and uninstalling

Note that each of these distributions has different associated libraries andother installed files which may conflict with or be wholly or partiallyoverwritten by one another. It is therefore advisable to ensure that you haveonly one distribution installed at any one time.

It is straightforward to uninstall the GCC Wiki distribution and instructionsare provided on the detailed instructions web page. Simply run the command:

sudo rm -r/usr/local/gfortran /usr/local/bin/gfortran


It is slightly more difficult to uninstall the R Project or HPC distribution. HPC distributes gfortran as a tar-file. Therefore each file contained in thetar-file should be removed. The easiest way to do this is probably to run thecommand:

For sh/bash:
for file in $(tar tfz[tar-file]); do sudo rm -f /$file; done

For csh/tcsh:
foreach file ( `tar tfz[tar-file]` )
sudo rm -f /$file

where [tar-file] is the package, for example gfortran-4.7-bin.tar.gz,gfortran-lion.tar.gz, gfortran-snwleo-intel-bin.tar.gz, etc. This will removeall files but not directories, which may contain other files that are not to be removed. To remove empty directories only, then run the command:

For sh/bash:
for file in $(tar tfz[tar-file]); do sudo rmdir -p /$file; done

For csh/tcsh:
foreach file ( `tar tfz[tar-file]` )
sudo rmdir -p /$file

The R Project distribution is a .pkg file and this adds another level ofcomplication. To list the files that were installed from this package, oneneeds to locate the 'receipt', which is a .bom file. On my system (Mac OS X10.8, Mountain Lion) the file is located at/private/var/db/receipts/ (was/private/var/db/receipts/ for Mac OSX 10.7, Lion; or /private/var/db/receipts/ for Mac OS X 10.6, Snow Leopard). To find the file, run a command such as:

sudo find / -iname'*fortran*.bom'

Once the appropriate file has been located, a list of files that have beeninstalled can be found by running the command:

lsbom -pF [bom-file]

Therefore, similarly to removing the HPC distribution, the files can beremoved by running commands such as:

For sh/bash:
for file in $(lsbom -pF[bom-file]); do sudo rm -f $file; done
for file in $(lsbom -pF[bom-file]); do sudo rmdir -p $file; done

Install Gfortran Windows 10

Download Gfortran Mac

For csh/tcsh:
foreach file ( `lsbom-pF [bom-file]` )
sudo rm -f $file

foreach file ( `lsbom-pF [bom-file]` )
sudo rmdir -p $file

Note that these commands should be run from the root directory (cd / first).

Last updated: 2020-09-02, M.Floyd (MIT)