How to Run Fortran F Code on Ubuntu
- 1). Click on the main menu in the top left-hand corner of your screen, then click on the "Terminal" option under the "Accessories" sub-menu.
- 2). Type "sudo apt-get gfortran" into the terminal window. Type in your administrative password when Ubuntu asks you for it. Wait for the compiler to finish installing.
- 3). Type "cd MyFortranDirectory" where "MyFortranDirectory" is the directory where you have the Fortran source code saved, into the terminal. For example, if you have the source code saved in the directory "/home/user" then type "cd /home/user" into the terminal.
- 4). Type "gfortran -o MyFortranProgram MyFortranSourceCode.f" into the terminal, where "MyFortranProgram" is the name you want to give the executable file this command will create, and "MyFortranSourceCode.f" is the name of the Fortran source code file from which you are creating that program. For example, if you have a Fortran source code file named "ProgramSource.f" and want to compile it into an executable called "FortranProgram" then you would type "gfortran -o FortranProgram ProgramSource.f" into the terminal. You may choose whatever name you wish for the executable file the command will create.
- 5). Type "./MyFortranProgram" to execute the program. Alternatively, you may double-click on the program's icon in the directory where you compiled it.
Source...