See also the Installation Guide for 64-bit GFortran binaries.
Here are the essential steps:
Download the GFortran binary
Install using the following command:
- tar -xzvf gfortran-4.5-linux-i686.tar.gz -C /
This will install gfortran in /usr/local/gfortran. You can then either set /usr/local/gfortran/bin to be in your search path or set up a link in your local ~/bin directory with this command as an example:
- ln -s /usr/local/gfortran/bin/gfortran ~/bin/gfc
Alternatively you can put links in the /usr/local/bin like this:
- ln -s /usr/local/gfortran/bin/gfortran /usr/local/bin/gfc
- ln -s /usr/local/gfortran/bin/gfortran /usr/local/bin/gfortran
You can read the man pages for gfortran with this:
- man -M /usr/local/gfortran/man gfortran
Assuming ~/bin is in your search path, you can invoke gfortran with:
- gfc --version or gfortran
Remember to use either -static or set an appropriate LD_LIBRARY_PATH otherwise the gfortran.so library might not be found or the wrong library used (e.g. older installation, system installation). You could also use -rpath (discouraged if you distribute your program).
Examples for setting the LD_LIBRARY_PATH
These examples assume that you installed gfortran at /opt/gcc-trunk.
Using the sh/bash/ksh etc. shell:
if [ -z "$LD_LIBRARY_PATH" ]; then LD_LIBRARY_PATH="/usr/local/gfortran/lib" else LD_LIBRARY_PATH="/usr/local/gfortran/lib:$LD_LIBRARY_PATH" fi export LD_LIBRARY_PATH
and an example using the csh/tcsh shell:
if !($?LD_LIBRARY_PATH) then setenv LD_LIBRARY_PATH "/usr/local/gfortran/lib" else setenv LD_LIBRARY_PATH "/usr/local/gfortran/lib:$LD_LIBRARY_PATH" endif
(One should not use "/usr/local/gfortran/lib:$LD_LIBRARY_PATH" if LD_LIBRARY_PATH is unset. The reason is that in that case the current directory is automatically included in the library path, which can be exploited by malicious users by placing a tinkered library in, e.g., /tmp.)