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.



I did as you have described
I did as you have described here and it seems that I can call the gfortran comand now. However i get the following message when try to compile. The following is the snapshot of my terminal
santosh-koiralas-macbook:~ Santosh$ gfortran input.f90
gfortran: error trying to exec 'as': execvp: No such file or directory
santosh-koiralas-macbook:~ Santosh$
Any suggestions would be appreciated
Santosh Koirala
Is XCode installed?
If not, you will need to do so before gfortran will work. (It should be on one of the disks that came with your Mac.)
I did install Xcode from the
I did install Xcode from the website. Now I have another problem. This is the snapshot of my terminal.
Last login: Sat Jun 27 11:38:24 on console
santosh-koiralas-macbook:~ Santosh$ gfortran input.f90
ld warning: duplicate dylib /usr/local/lib/libgcc_s.1.dylib
santosh-koiralas-macbook:~ Santosh$
I have no idea whats going on. Any suggestions. Thank you.
Santosh Koirala
What did you do after installing XCode
Did you reinstall the gfortran package? If not, it may not have configured everything correctly.
Thanks
I have been finally able to install the fortran. The trick was to install the X-Code first and install the gfortran compiler. Thank ya'll for your help.
Sincerely
Santosh Koirala
P.S. For anyone having a similar problem please visit this site: http://www.webmo.net/support/fortran_osx.html. It might be helpfu
GFortran and NetBeans IDE
Hi Ljuba,
Many thanks for putting up this useful post. I do have one small problem that I am unsure how to resolve.
I use the NetBeans IDE which is currently working well with the GNU C/C++ compilers bundled with XCode. NetBeans can utilise the same functionality provided by a fortran compiler but because GCC is currently in
/usr/binand GFortran installs to/usr/local/binI cannot get them to work together because they are in different base directories.Do you know of a method for merging the GFortran installation made by this package with the existing GCC compiler located in
/usr/bin?Cheers,
Phil