1 安装前准备
1.1 安装环境
本机安装环境如下:
运行环境 | |
---|---|
操作系统 | Ubuntu 22.04.4 LTS (Jammy Jellyfish) |
CPU | Intel® Core™ i5-12400 |
显卡 | NVIDIA GeForce RTX 4090 |
1.2 验证 GPU 是否为 NVIDIA GPU
在命令行输入以下代码,以验证您的 GPU 是否是 NVIDIA GPU
lspci | grep -i nvidia
2 安装 NVIDIA 相关的依赖
2.1 查找支持的驱动
在命令行输入以下代码,查找本机支持的 NVIDIA 显卡驱动版本:
ubuntu-drivers devices
这将列出系统支持的所有 NVIDIA 驱动程序,选择最新版本的驱动程序进行安装:
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00002684sv00001458sd000040E4bc03sc00i00
vendor : NVIDIA Corporation
manual_install: True
driver : nvidia-driver-535-server - distro non-free
driver : nvidia-driver-535 - distro non-free recommended
driver : nvidia-driver-545 - distro non-free
driver : nvidia-driver-535-server-open - distro non-free
driver : nvidia-driver-545-open - distro non-free
driver : nvidia-driver-535-open - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
2.2 查找可安装的驱动
在命令行输入以下代码,查找本机可安装的 NVIDIA 显卡驱动:
sudo apt search nvidia-driver | grep nvidia-driver
这将列出当前源下所有可下载的 NVIDIA 驱动程序,例如本机可下载NVIDIA显卡驱动如下:
Transitional package for nvidia-driver-390
Transitional package for nvidia-driver-390
nvidia-driver-390/jammy-security,jammy-updates 390.157-0ubuntu0.22.04.2 amd64
nvidia-driver-418/jammy 430.50-0ubuntu3 amd64
Transitional package for nvidia-driver-430
nvidia-driver-418-server/jammy-security,jammy-updates 418.226.00-0ubuntu5~0.22.04.1 amd64
nvidia-driver-430/jammy 440.100-0ubuntu1 amd64
Transitional package for nvidia-driver-440
nvidia-driver-435/jammy 455.45.01-0ubuntu1 amd64
Transitional package for nvidia-driver-455
nvidia-driver-440/jammy 450.119.03-0ubuntu1 amd64
Transitional package for nvidia-driver-450
nvidia-driver-440-server/jammy-security,jammy-updates 450.248.02-0ubuntu0.22.04.1 amd64
Transitional package for nvidia-driver-450-server
nvidia-driver-450/jammy 460.91.03-0ubuntu1 amd64
Transitional package for nvidia-driver-460
nvidia-driver-450-server/jammy-security,jammy-updates 450.248.02-0ubuntu0.22.04.1 amd64
nvidia-driver-455/jammy 460.91.03-0ubuntu1 amd64
Transitional package for nvidia-driver-460
nvidia-driver-460/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
Transitional package for nvidia-driver-470
nvidia-driver-460-server/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
Transitional package for nvidia-driver-470-server
nvidia-driver-465/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
Transitional package for nvidia-driver-470
nvidia-driver-470/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
nvidia-driver-470-server/jammy-security,jammy-updates 470.256.02-0ubuntu0.22.04.1 amd64
nvidia-driver-495/jammy-security,jammy-updates 510.108.03-0ubuntu0.22.04.1 amd64
Transitional package for nvidia-driver-510
nvidia-driver-510/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
Transitional package for nvidia-driver-535
nvidia-driver-510-server/jammy-security,jammy-updates 515.105.01-0ubuntu0.22.04.1 amd64
Transitional package for nvidia-driver-515-server
nvidia-driver-515/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
Transitional package for nvidia-driver-535
nvidia-driver-515-open/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
Transitional package for nvidia-driver-535
nvidia-driver-515-server/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
Transitional package for nvidia-driver-535-server
nvidia-driver-520/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
Transitional package for nvidia-driver-535
nvidia-driver-520-open/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
Transitional package for nvidia-driver-535
nvidia-driver-525/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
nvidia-driver-525-open/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
nvidia-driver-525-server/jammy-security,jammy-updates 525.147.05-0ubuntu2.22.04.1 amd64
nvidia-driver-530/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
Transitional package for nvidia-driver-535
nvidia-driver-530-open/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
Transitional package for nvidia-driver-535-open
nvidia-driver-535/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
nvidia-driver-535-open/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
nvidia-driver-535-server/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
nvidia-driver-535-server-open/jammy-security,jammy-updates 535.183.01-0ubuntu0.22.04.1 amd64
nvidia-driver-545/jammy-updates 545.29.06-0ubuntu0.22.04.2 amd64
nvidia-driver-545-open/jammy-updates 545.29.06-0ubuntu0.22.04.2 amd64
nvidia-driver-550/jammy-security,jammy-updates,now 550.90.07-0ubuntu0.22.04.1 amd64 [installed]
nvidia-driver-550-open/jammy-security,jammy-updates 550.90.07-0ubuntu0.22.04.1 amd64
nvidia-driver-550-server/jammy-security,jammy-updates 550.90.07-0ubuntu0.22.04.1 amd64
nvidia-driver-550-server-open/jammy-security,jammy-updates 550.90.07-0ubuntu0.22.04.1 amd64
2.3 安装 Nvidia 驱动
选择2.1和2.2中都有的驱动程序进行安装,参考以下命令,根据自己的显卡安装最新的显卡驱动及其对应的显卡工具包
# 下载并安装显卡工具包
sudo apt install nvidia-utils-545
# 下载并安装显卡驱动
sudo apt install nvidia-driver-545
# 重启电脑
sudo reboot
2.4 安装内核头文件和开发包
确保已安装当前运行内核的头文件和开发包:
sudo apt-get install linux-headers-$(uname -r)
2.5 安装 cuda 11.8
从 CUDA Toolkit Archive 下载 CUDA Toolkit 11.8.0 工具包。
根据你的系统,选择并下载并安装适用于您的系统的 CUDA 工具包,例如我们的系统选择以下配置项。
对于 Ubuntu 22.04 LTS x86_64 系统,执行以下步骤:
# 下载 cuda 工具包
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
# 安装 cuda 工具包
sudo sh cuda_11.8.0_520.61.05_linux.run
在安装过程中,按以下步骤操作:
- 选择
continue
并按Enter
键。 - 输入
accept
并按Enter
键。 - 使用
上下键
和空格键
选择需要安装的组件(通常只需选择CUDA Toolkit 11.8
),然后选择install
并按Enter
键。
2.6 配置环境变量
添加 CUDA 路径到环境变量:
sudo gedit ~/.bashrc
在文件末尾添加以下行:
export PATH=$PATH:/usr/local/cuda-11.8/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64
保存并关闭文件,然后刷新环境变量:
source ~/.bashrc
3 安装 Paddle 框架
3.1 安装 miniconda
前往 Miniconda 官方网站 下载最新的 Miniconda 版本。下载并安装 Miniconda:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
- 安装过程中按以下步骤操作:
- 按
Enter
键。 - 按
空格键
跳过安装协议。 - 输入
yes
并按Enter
键继续安装。
- 按
完成安装后,初始化 conda:
~/miniconda3/bin/conda init bash
source ~/.bashrc
3.2 创建并初始化一个 python 环境
如果网络环境在国内建议配置 conda 源为中科大源:
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
创建并激活一个新的 Python 环境:
conda create -n paddlepaddle python=3.10
conda activate paddlepaddle
3.3 使用 pip 安装 Paddle 框架
由于 Conda 镜像源可能导致 PaddlePaddle GPU 版本下载困难,建议使用 pip 安装:
python -m pip install paddlepaddle-gpu==3.0.0b1 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
3.4 验证 Paddle 框架
安装完成后,验证 PaddlePaddle 是否安装成功:
python
在 Python 交互环境中输入以下命令:
# 弹出 Python 窗口后继续执行以下命令
>>> import paddle
>>> paddle.utils.run_check()
>>> exit()
如果没有错误信息,则说明 PaddlePaddle 安装成功。