Debian中Fortran版本更新指南(以gfortran為例)
在更新Fortran編譯器前,需先同步本地軟件包列表與遠程倉庫的最新信息,確保獲取到最新的版本信息。執行以下命令:
sudo apt update
此命令會刷新/etc/apt/sources.list中定義的軟件源,獲取最新的包版本、依賴關系等數據。
若已安裝gfortran,可直接通過以下命令升級到倉庫中可用的最新版本:
sudo apt install --only-upgrade gfortran
--only-upgrade參數確保僅升級已安裝的gfortran包,避免意外安裝新包(若未安裝,此命令會報錯)。
若無需限制僅升級,可直接運行:
sudo apt install gfortran
系統會自動檢測當前安裝的gfortran版本,并升級到倉庫中的最新版本。
若需安裝特定版本的gfortran(如gfortran-9、gfortran-10),需明確指定包名(版本號需與Debian倉庫中提供的版本一致)。例如,安裝gfortran-9:
sudo apt install gfortran-9
安裝完成后,需通過update-alternatives工具切換默認版本(詳見“四、切換默認版本”)。
更新完成后,通過以下命令驗證gfortran的版本及支持的Fortran標準:
gfortran --version
輸出示例:
GNU Fortran (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
其中,“12.2.0”為gfortran的版本號,版本號越高,支持的Fortran標準越新(如Fortran 2003/2008)。
若系統中安裝了多個gfortran版本(如gfortran-9、gfortran-10),可通過update-alternatives工具設置默認版本:
gfortran版本:sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-9 90sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-10 10090、100為優先級,數值越大優先級越高)sudo update-alternatives --config gfortran若需使用Intel Fortran等商業編譯器,需從官方網站下載Linux版本安裝包,按照指南手動安裝。安裝后需設置環境變量(如PATH),可將以下命令添加到~/.bashrc中實現永久生效:
source /opt/intel/oneapi/setvars.sh
(路徑需根據實際安裝目錄調整)。
sudo apt install liblapack-dev libblas-devgfortran或使用Intel Fortran。