在 CentOS 上“升级 Fortran 版本”通常指的是 升级 Fortran 编译器(如 gfortran)的版本,因为 Fortran 本身是语言标准,实际使用的是编译器。下面按常见场景给你说明。
gfortran --version
如果提示 command not found,说明还没装:
yum install gcc-gfortran
CentOS 7 默认源:
CentOS 8 / Stream:
升级方式(仅限系统源内):
yum update gcc-gfortran
⚠️ 这种方式 无法跨越 major 版本,比如 CentOS 7 无法升到 gfortran 11。
yum install centos-release-scl
yum install devtoolset-11-gcc-gfortran
scl enable devtoolset-11 bash
gfortran --version
echo "source /opt/rh/devtoolset-11/enable" >> ~/.bashrc
yum groupinstall "Development Tools"
yum install gmp-devel mpfr-devel libmpc-devel
wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
tar -xzf gcc-13.2.0.tar.gz
cd gcc-13.2.0
./configure --enable-languages=fortran --disable-multilib
make -j$(nproc)
make install
⚠️ 编译耗时较长,建议服务器操作。
# 官方安装后
source /opt/intel/oneapi/setvars.sh
ifort --version
conda create -n fortran gfortran
conda activate fortran
gfortran --version
✅ 强烈推荐新手/科研用户用 Conda
| 场景 | 推荐方式 |
|---|---|
| CentOS 7 想用新 Fortran | devtoolset-11 |
| 需要最新标准 | 源码编译 / Conda |
| 科研计算 | Conda / Intel |
| 不想动系统 | SCL 或 Conda |
如果你能告诉我:
我可以给你精确到命令的方案。