该文档存在错误,若想达到相同的目的,请对错误指令或者错误的软件源进行修改。
时间: 2024-12-23 20:15:48 浏览: 18
### 文档中的错误及修正建议
#### 1. 错误:Ubuntu 版本不匹配
**原文:**
```bash
deb http://mirrors.aliyun.com/ubuntu/ xenial main
...
```
**修正:**
由于文档中提到的是 Ubuntu 22.04.3,而 `xenial` 是 Ubuntu 16.04 的代号,应使用 `jammy`(对应 Ubuntu 22.04)。
```bash
deb http://mirrors.aliyun.com/ubuntu/ jammy main
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main
deb http://miriors.aliyun.com/ubuntu/ jammy-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main
deb http://mirrors.aliyun.com/ubuntu/ jammy universe
deb-src http://mirrors.aliyun.com/ubuntu/ jammy universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main
deb http://mirrors.aliyun.com/ubuntu/ jammy-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security universe
```
#### 2. 错误:GCC/G++/GFortran 版本安装命令不正确
**原文:**
```bash
sudo apt-get install gcc-9=9.5.0-1ubuntu1~22.04
sudo apt-get install g++-9=9.5.0-1ubuntu1~22.04
sudo apt-get install gfortran-9=9.5.0-1ubuntu1~22.04
```
**修正:**
这些版本号可能不存在或不准确。应直接安装 GCC 9 及其相关工具链。
```bash
sudo apt-get install gcc-9 g++-9 gfortran-9
```
#### 3. 错误:配置 NetCDF 和 HDF5 时路径不一致
**原文:**
```bash
--with-slib=/home/bing3/local/netcdf4
```
**修正:**
`--with-slib` 应改为 `--with-zlib` 或者删除此选项,因为 `zlib` 已经在前面指定了。
```bash
./configure --prefix=/home/bing3/local/netcdf4 --with-zlib=/home/bing3/local/netcdf4 --enable-shared --enable-hl
```
#### 4. 错误:OpenMPI 配置路径不一致
**原文:**
```bash
./configure --prefix=/home/bing3/local/openmpi
```
**修正:**
确保路径与实际安装路径一致。
```bash
./configure --prefix=/home/bing3/local/openmpi
```
### 修改后的完整脚本
```bash
# 编辑 GRUB 配置文件以解决开机黑屏问题
sudo vim /etc/default/grub
"""
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="fsck.mode=skip quiet splash nomodeset"
GRUB_CMDLINE_LINUX=""
"""
# 更新 GRUB 配置
sudo update-grub
# 更改软件源
sudo vim /etc/apt/sources.list
"""
deb http://mirrors.aliyun.com/ubuntu/ jammy main
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main
deb http://mirrors.aliyun.com/ubuntu/ jammy universe
deb-src http://mirrors.aliyun.com/ubuntu/ jammy universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main
deb http://mirrors.aliyun.com/ubuntu/ jammy-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security universe
"""
# 更新软件源
sudo apt-get update
# 安装 GCC、G++、GFortran 默认版本
sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install gfortran
# 安装 GCC 9 及其相关工具链
sudo apt-get install gcc-9 g++-9 gfortran-9
# 调整编译器权重
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 50
sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-11 40
sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-9 50
# 根据需要选择编译器
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
sudo update-alternatives --config gfortran
# 安装和配置 NetCDF4 相关库
# 安装目录为 ~/local/netcdf4
# 安装 zlib
tar -zxvf zlib-1.2.12.tar.gz
cd zlib-1.2.12
./configure --prefix=/home/bing3/local/netcdf4
make
make check
make install
# 安装 HDF5
tar -zxvf hdf5-1.10.5.tar.gz
cd hdf5-1.10.5
./configure --prefix=/home/bing3/local/netcdf4 --with-zlib=/home/bing3/local/netcdf4 --enable-shared --enable-hl
make
make check
make install
# 安装 m4
sudo apt-get install m4
# 安装 NetCDF C
tar -zxvf netcdf-c-4.8.1.tar.gz
cd netcdf-c-4.8.1
LDFLAGS=-L/home/bing3/local/netcdf4/lib CPPFLAGS=-I/home/bing3/local/netcdf4/include ./configure --prefix=/home/bing3/local/netcdf4 --disable-dap
make
make check
make install
# 安装 NetCDF Fortran
tar -zxvf netcdf-fortran-4.5.3.tar.gz
cd netcdf-fortran-4.5.3
LDFLAGS=-L/home/bing3/local/netcdf4/lib CPPFLAGS=-I/home/bing3/local/netcdf4/include ./configure --prefix=/home/bing3/local/netcdf4
make
make check
make install
# 安装 OpenMPI
tar -zxvf openmpi-4.1.0.tar.gz
cd openmpi-4.1.0
./configure --prefix=/home/bing3/local/openmpi
make
make check
make install
# 安装 Anaconda3 并安装 NetCDF4 和 PyNcView
sh Anaconda3-2020.07-Linux-x86_64.sh
pip install netcdf4
pip install pyncview
```
以上是文档中错误的部分及其修正建议,希望对你有帮助!
阅读全文