该文档存在错误,若想达到相同的目的,请对错误指令或者错误的软件源进行修改。注意安装的安装 GCC 及其相关工具链是9.5版本。
时间: 2024-12-22 13:32:45 浏览: 6
php源代码安装常见错误与解决办法分享
在文档中存在一些错误和不一致的地方,以下是修正后的步骤:
### 解决开机黑屏(驱动)问题
编辑 `/etc/default/grub` 文件:
```bash
sudo vim /etc/default/grub
```
将以下内容添加或修改:
```plaintext
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 配置:
```bash
sudo update-grub
```
### 修改软件源
编辑 `/etc/apt/sources.list` 文件:
```bash
sudo vim /etc/apt/sources.list
```
将以下内容替换为适用于 Ubuntu 22.04 的阿里云镜像源:
```plaintext
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
```
更新软件源:
```bash
sudo apt-get update
```
### 安装 GCC 及其相关工具链 9.5 版本
安装默认版本:
```bash
sudo apt-get install gcc
sudo apt-get install g++
sudo apt-get install gfortran
```
安装特定版本 9.5:
```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
```
调整编译器优先级:
```bash
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
```
选择编译器:
```bash
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
sudo update-alternatives --config gfortran
```
### 编译 NetCDF4
#### 安装依赖
```bash
sudo apt-get install m4
```
#### 编译 zlib
```bash
tar -zxvf zlib-1.2.12.tar.gz
cd zlib-1.2.12
./configure --prefix=/home/your_username/local/netcdf4
make
make check
make install
```
#### 编译 HDF5
```bash
tar -zxvf hdf5-1.10.5.tar.gz
cd hdf5-1.10.5
./configure --prefix=/home/your_username/local/netcdf4 --enable-hl
make
make check
make install
```
#### 编译 NetCDF-C
```bash
tar -zxvf netcdf-c-4.8.1.tar.gz
cd netcdf-c-4.8.1
LDFLAGS=-L/home/your_username/local/netcdf4/lib CPPFLAGS=-I/home/your_username/local/netcdf4/include ./configure --prefix=/home/your_username/local/netcdf4 --disable-dap
make
make check
make install
```
#### 编译 NetCDF-Fortran
```bash
tar -zxvf netcdf-fortran-4.5.3.tar.gz
cd netcdf-fortran-4.5.3
LDFLAGS=-L/home/your_username/local/netcdf4/lib CPPFLAGS=-I/home/your_username/local/netcdf4/include ./configure --prefix=/home/your_username/local/netcdf4
make
make check
make install
```
#### 编译 OpenMPI
```bash
tar -zxvf openmpi-4.1.0.tar.gz
cd openmpi-4.1.0
./configure --prefix=/home/your_username/local/openmpi
make
make check
make install
```
### 安装 Anaconda 和相关 Python 包
下载并安装 Anaconda:
```bash
sh Anaconda3-2020.07-Linux-x86_64.sh
```
安装 NetCDF4 和 PyNcView:
```bash
pip install netcdf4
pip install pyncview
```
以上步骤已修正了文档中的错误,并确保安装的是 GCC 9.5 及其相关工具链。请注意将 `your_username` 替换为你自己的用户名。
阅读全文