在 Debian 中更新 Fortran 相关工具
一、使用 APT 的标准更新方式
sudo apt update
sudo apt upgrade
sudo apt install --only-upgrade gfortran
sudo apt install build-essential
gfortran --version
上述方法适用于 Debian 及大多数基于 Debian 的发行版,使用系统仓库即可完成更新,简单且可靠。
二、安装或切换到特定版本的 gfortran
apt search gfortran- | grep -E '^gfortran-[0-9]+$'
sudo apt install gfortran-12
gfortran-12 -o hello hello.f90
三、升级到新版本 GCC 以更新 gfortran
# 下载并解压 GCC 源码(以 7.3.0 为例)
wget http://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
tar -xzf gcc-7.3.0.tar.gz
cd gcc-7.3.0
./contrib/download_prerequisites
mkdir build && cd build
../configure --enable-checking=release \
--enable-languages=c,c++,fortran \
--disable-multilib \
--prefix=/opt/gcc-7.3.0
make -j"$(nproc)"
sudo make install
# 配置环境(示例)
echo 'export PATH=/opt/gcc-7.3.0/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/opt/gcc-7.3.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
gcc -v
gfortran -v
四、其他 Fortran 工具与生态
# 下载并解压 fpm(示例版本 v0.9.0)
wget https://github.com/fortran-lang/fpm/releases/download/v0.9.0/fpm-0.9.0-linux-x86_64.tar.gz
tar -xzf fpm-0.9.0-linux-x86_64.tar.gz
echo 'export PATH=/path/to/fpm-0.9.0-linux-x86_64/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
五、常见问题与排查