在 Ubuntu 上安装 Fortran 编译器(最常用的是 gfortran),步骤如下:
sudo apt update
sudo apt install gfortran
gfortran --version
如果显示版本信息,说明安装成功。
如果你还需要 C/C++ 编译器:
sudo apt install build-essential gfortran
nano hello.f90
内容如下:
program hello
print *, "Hello, Fortran!"
end program hello
gfortran hello.f90 -o hello
./hello
输出:
Hello, Fortran!
sudo apt install flang
如果你是用于科学计算 / 数值模拟 / 老代码移植,可以告诉我具体用途,我可以给你更合适的安装建议。