CentOS 7系统自带GNU为4.8.x版本,安装WRF v4.2以上版本会报错,需升级GNU版本。
以root登录系统,添加SCL存储库,执行以下命令:
yum install centos-release-scl
安装DevToolSet,其中包含了较高版本的GCC和gfortran(以9.x.x版本为例):
yum install devtoolset-9-gcc-gfortran
如需稍低版本(如7.x.x版本):
yum install devtoolset-7-gcc-gfortran
使用以下命令启用DevToolSet环境:
scl enable devtoolset-9 bash
或
scl enable devtoolset-7 bash
确认gfortran已成功安装,执行以下命令进行验证:
gfortran --version
执行完上述命令服务器中GCC版本
GNU Fortran (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
这样,在CentOS 7中就可以安装并使用较高版本的gfortran了。使用scl命令启用DevToolSet环境后,系统将使用该环境中的工具链,包括gfortran。注意,每次使用gfortran之前都需要启用DevToolSet环境。
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。
如果要长期使用xinbanben GNU的话,使用命令:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
或
echo "source /opt/rh/devtoolset-7/enable" >>/etc/profile
之后退出shell重新打开就默认使用新版本GNU了。