在 Ubuntu 上不是“装不了 Fortran”,而是没有预装 Fortran 编译器,或者你用的方法不对。下面把常见原因和解决办法说清楚。
Ubuntu 默认只装了基础系统,gcc / g++ 也不一定装,更不会自动装 gfortran。
所以你直接运行:
fortran
或
gfortran
会得到:
Command 'gfortran' not found
✅ 这是正常现象,不是系统不支持。
sudo apt update
sudo apt install gfortran
安装完成后测试:
gfortran --version
写个测试程序:
program hello
print *, "Hello Fortran"
end program hello
编译运行:
gfortran hello.f90 -o hello
./hello
sudo apt update
不更新可能找不到包。
检查:
lsb_release -a
如果是很老的 Ubuntu(如 14.04 已 EOL),需要换源。
很多云服务器默认 不装编译工具链。
可以一次性装完整开发工具:
sudo apt install build-essential gfortran
Fortran 是语言,不是命令。
你用的应该是:
gfortran(GNU)ifort(Intel,需单独安装)sudo apt install intel-oneapi-compiler-fortran
或从 Intel 官网下载 oneAPI。
Ubuntu 能装 Fortran,只是默认没装。
装一个
gfortran就行了。
如果你愿意,可以把你看到的具体报错信息贴出来,我可以直接帮你定位。