New to UNIX on a Mac? Want to install gfortran? Read this!
The gfortran installer package (http://www.macresearch.org/xcode_gfortran_plugin_update) offered on MacResearch.org is great, but there is one last step of the installation if you want to be able to compile simple fortran programs from the command line. This is for people new to UNIX or the Mac. I share this as I recently discovered it myself.
The gfortran compiler executable is installed in the hidden folder /usr/local/bin, which you can access by the terminal by typing: cd /usr/local/bin . Once you install the gfortran package and try typing gfortran, you'll get the error, "-bash: gfortran: command not found". This is because the terminal doesn't know about gfortran as a general command that you might want to use. (If you were to type /usr/local/bin/gfortran it would work). If you'd like to be able to compile fortran code from anywhere in your system from the command line, you need to tell your terminal shell where gfortran is, by doing the following:
In the Terminal:
1. Go to your Mac home folder: cd ~
2. List the files there: ls -al
3. Check for a file called .bash_profile (the period means it's a hidden file):
4. If it doesn't exist you need to create it (using any text editor, just make sure you save it to your home folder) and have the first line be: export PATH=/usr/local/bin:$PATH
5. Remember to hit return after that line. If you already have a .bash_profile file, just add the above line to the bottom.
6. Doing this tells your terminal shell to give you access to the commands (in this case, gfortran) in the /usr/local/bin directory.
Now you can compile fortran code by typing: gfortran anywhere in the terminal. The specific syntax for simple programs goes like this:
gfortran -o name_of_compiled_program source_file_1 source_file_2
The -o tells gfortran that the next file name is the desired compiled program name. Any files that follow are the source files. I hope this helps someone out there.


