1. NVIDIA graphics card driver installation
There are three ways to install the nvidia graphics card driver: using the ubuntu additional driver; using the command line to install; using the .run file to install,
1.1 How to add drivers to ubuntu
Click Additional Drivers in the menu to select the appropriate driver version to install, this method is the most convenient and quick (but sometimes it will overturn)
1.2 Installation via command line
update all packages
sudo add-apt-repository ppa:graphics-drivers/ppa # 加入官方ppa源
sudo apt update # 检查软件包更新列表
apt list --upgradable # 查看可更新的软件包列表
sudo apt upgrade # 更新所有可更新的软件包
Install graphics driver
ubuntu-drivers devices # ubuntu检测n卡的可选驱动
sudo apt install nvidia-driver-510 # 根据自己的n卡可选驱动下载显卡驱动
1.3 .run file installation
For details, see my other blog Ubunut20.04/22.04 install NVIDIA driver
This method is the most troublesome operation steps (least easy to overturn)
1.4 Dual Graphics Driver Selection
If there are two independent graphics cards of different brands, you need to choose an nvidia graphics card. There are two methods, as follows:
1. You can open the terminal and use nvidia-settings
the command to select, click Prime profiles, select NVIDIA (Performance Mode)
to adjust and restart the system
2. You can also use prime -select command
sudo prime-select query //查看当前使用显卡
sudo prime-select nvidia //使用nvidia显卡
sudo prime-select intel //使用intel显卡
After using sudo prime-select nvidia
the command you can reboot
reboot the system with
1.4 Verify the NVIDIA driver installation
You can use the following command to check whether the nvidia driver is loaded
sudo nvidia-settings # 更改Nvidia驱动设置
nvidia-smi # 查看显卡基本信息
If there is a problem, you can check the reason with gpu-manager. You can mainly check whether it is consistent with the red box in the figure below. If there is a problem, analyze the specific problem in detail
sudo gpu-manager
Two, CUDA installation
2.1 View version correspondence
First, you need to go to NVIDIA CUDA Toolkit Release Notes to check the CUDA version corresponding to your graphics card driver. The following figure shows the version correspondence: You
can also get the driver version by checking nvidia-smi. You can query the above table through the version number, or you can find it in this Get the highest cuda version corresponding to the driver version in the interface, that is, CUDA Version 11.7
2.2 Download CUDA
The website of cuda official website is CUDA Toolkit Archive
. Here I chose CUDA version 11.7 to install. You can install the version you need to configure. The version output in nvidia-smi can be supported up to the version. Select the corresponding option
according to your own system conditions. The last one is runfile. It is not easy to go wrong
Use the following command to download the file
wget https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda_11.7.0_515.43.04_linux.run
Download completed
2.3 CUDA installation
Then follow the steps to install
sudo sh cuda_11.7.0_515.43.04_linux.run
Select continue to continue
, enter accept,
and press Enter. The first one is to select the driver, and press Enter to cancel it, because we already have the driver installed, and then move to install.
When the following summary appears, the installation is complete
and then configure the environment variable in .bashrc
sudo gedit ~/.bashrc
Add the following field after the last line of the opened file:
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64
Then refresh the environment variables
source ~/.bashrc
Use the following command to view the CUDA installation
nvcc -V
3. Install cudnn
If you want to run deep learning, you must install it, and you don’t need to install it!
3.1 Download and install
Go to the official website to download: https://developer.nvidia.com/rdp/cudnn-download
Select Local Installer for Linux x86_64 (Tar) to download,
unzip and enter this directory to copy related files
cd cudnn-linux-x86_64-8.6.0.163_cuda11-archive
sudo cp include/cudnn*.h /usr/local/cuda/include
sudo cp -p lib/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
3.2 Check the installed version
For older versions of cuDNN, use the following command to view the version number:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
The version number of the higher version of cuDNN is no longer in cudnn.h, but in cudnn_version.h, we also need to copy cudnn_version.h to /usr/local/cuda/include, and then use the following command to view:
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2