Ubuntu installation: graphics driver, CUDA, Anaconda
Install CUDA and Pytorch in Windows environment, see: Getting started with Pytorch: 3. Installation
environment :x86_64
Linux ubuntu18 4.150.0-20-generic
Summary
This blog summarizes the methods of installing graphics card drivers, CUDA and Anaconda in the Ubuntu system in order to deepen understanding and memory
1. Install the NVIDIA graphics card driver
# 1.查看显卡型号
# 正常实体机的显卡型号是一个16进制的代码,可以通过该代码在网上查询具体型号,如:01:00.0 VGA compatible controller:NVIDIA Corporation Device 1f06 (rev a1)
# 虚拟机的显卡型号会显示虚拟机的适配器,如:00:0f.0 VGA compatible controller: VMware SVGA II Adapter
lspci | grep -i vga
# 2.安装ubuntu显卡驱动软件
# 查看设备可用和推荐的显卡驱动版本
ubuntu-drivers devices
# 若上述命令没有返回,则先更新软件库
# 增加apt的更新源paa
sudo add-apt-repository ppa:graphics-drivers/ppa
# 更新软件库
sudo apt-get update
# 3.按照ubuntu-drivers devices remcommended的驱动进行安装(如下图1所示)
sudo apt-get install nvidia-470 nvidia-settings nvidia-prime
sudo apt install nvidia-utils-470
# 或者可以让ubuntu驱动自动选择安装合适的版本
sudo ubuntu-drivers autoinstall
# 4.查看英伟达显卡信息(显示一次当前GPU占用情况)
nvidia-smi
# 若显示仍无驱动,则重启计算机(服务器)再查看
reboot
# 显示GPU信息(每秒刷新一次并显示)
nvidia-smi -l
# 显示GPU信息(每n+1秒显示一次)
watch -n {
n} nvidia-smi
# 显卡信息解释如下图2所示
![](https://img-blog.csdnimg.cn/65ebcf5470b44a42902704bcfdf66d28.png)
![](https://img-blog.csdnimg.cn/9be613e265db43f1bcf8e9376601d21a.png)
item | explain |
---|---|
first row | Graphics card information, driver version, and compatible CUDA version |
Fan | speed of the fan |
Temp | temperature in degrees Celsius |
Perf | Performance status, from P0 to P12, P0 indicates the maximum performance, P12 indicates the minimum performance of the state |
Pwr | energy consumption |
Bus-ld | Information about the GPU bus |
Disp.A | Display Active, indicating whether the display of the GPU is initialized |
Memory Usage | memory usage |
GPU-Util | GPU utilization |
Volatile、Uncorr. ECC | Information about ECC |
Compute M | Calculation mode |
The third row | Indicates the video memory usage of each process |
2. Install CUDA
Ⅰ. Download and install CUDA toolkit
Enter the download page of CUDA toolkit , select the corresponding version and system:
![](https://img-blog.csdnimg.cn/a09936fd76314c96ad6e1f982f417a75.png)
![](https://img-blog.csdnimg.cn/1b47935e3c3c40069f36494da01db19a.png)
key issues
There are three installation methods here: local installation package deb (local), network installation package deb (network), local script runfile (local)
First of all, the first two installation methods may have the problem that the public key cannot be configured and the apt download source cannot be set. For specific solutions, please refer to this blog
Secondly, during the installation process, if the graphics card driver version corresponding to the target CUDA toolkit does not exactly match the original graphics card driver version on the machine, it will prompt a dependency error and fail to install.
Finally, some blogs will give aptitude
a solution to install by using, but this method will uninstall the original graphics card driver on the machine by default, and install the graphics card driver corresponding to the target CUDA toolkit, and errors will occur during this process.
To sum up, we choose to use runfile
the installation method. Installation by usage runfile
is not a direct solution to the problem of incomplete correspondence of the above versions, but it provides us with the option to manually choose to install only the CUDA toolkit without installing the driver :
During installation, it will still prompt that the corresponding version of the graphics card driver of the target CUDA toolkit has not been found. It is recommended that we install the graphics card driver of its version. At this time, we type, and then type to agree to the user continue
agreement accept
, and then move the cursor to the driver, type 回车
, to cancel Driver installation:
![](https://img-blog.csdnimg.cn/51ab9ef58b38481d9940a21e1d1faebc.png)
![](https://img-blog.csdnimg.cn/55a1545b6dfd459ea4fe6445b9c9100d.png)
The installed cuda toolkit is in /usr/local/
the directory
Configure environment variables for CUDA toolkit:
# 编辑配置文件
vim ~/.bashrc
# 在配置文件末尾配置环境变量
export CUDA_HOME=/usr/local/cuda-{
version}
export PATH="/usr/local/cuda-{version}/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-{version}/lib64:$LD_LIBRARY_PATH"
alias sudo='sudo env PATH=$PATH'
# 刷新配置文件
source ~/.bashrc
Verify installation
nvcc -V
Ⅱ. Install cuDNN
Enter the cuDNN download page (you need to register an account before downloading cuDNN), and select the deb package according to the applicable CUDA version and system type of the machine (you can also download the Linux x86_64 Tar package for file replacement)
![](https://img-blog.csdnimg.cn/7ab3b683bcd344978ca6fc4cd7c3ccf8.png)
Unzip the deb package and install it
3. Install Anaconda
Enter the Anaconda download page , click Download
to automatically select the appropriate version of the installation package
# 进入下载目录
cd /home/{
用户名}/[下载|download]
# 为文件赋权限
chmod -R 777 Anaconda3-2023.0-1-Linux-x86_64.sh
# 执行脚本
sudo ./Anaconda3-2023.0-1-Linux-x86_64.sh
# 键入回车继续安装
# 一直回车看到协议
# 输入yes继续安装
# 回车确定默认安装目录或手动输入安装目录
Configure environment variables for annaconda
# 编辑配置文件
vim ~/.bashrc
# 在配置文件末尾配置环境变量(此处使用的是系统默认安装路径
export PATH="/home/{用户名}/anaconda3/bin:$PATH"
Verify installation
conda --version