在 Ubuntu 上升级 Fortran 编译器(通常是 gfortran),可以按下面几种方式操作,根据你的需求选择。
sudo apt update
sudo apt upgrade gfortran
gfortran --version
这种方式升级的是 Ubuntu 官方仓库中的版本,可能不是最新。
Ubuntu 常同时提供多个 GCC 版本,例如 gfortran-9、gfortran-10、gfortran-11 等。
apt-cache search gfortran
sudo apt install gfortran-11
sudo update-alternatives --config gfortran
按提示选择你想要的版本。
如果你的 Ubuntu 版本较旧,官方仓库没有新 gfortran,可以用 PPA。
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
例如:
sudo apt install gfortran-12
sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-12 100
sudo update-alternatives --config gfortran
适合需要最新 Fortran 标准支持或特殊平台。
sudo apt install build-essential
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
./contrib/download_prerequisites
mkdir build && cd build
../configure --enable-languages=fortran
make -j$(nproc)
sudo make install
Intel Fortran (ifort / ifx)
适合高性能计算
https://www.intel.com/content/www/us/en/developer/tools/oneapi/fortran-compiler.html
Flang (LLVM Fortran)
sudo apt install flang
gfortran 是 GCC 的一部分,版本与 GCC 对应。
可能是标准变化,加:
gfortran -std=legacy old.f90
如果你能告诉我:
lsb_release -a)我可以给你精确命令。