NVIDIA Environments
On Ubuntu Server 22.04 / 26.04
Driver
Disable the open-source
nouveau driver first!# check the nouveau driver
lsmod | grep nouveau
# if has output, disable it
echo "blacklist nouveau" | sudo tee /etc/modprobe.d/disable-nouveau.conf
echo "options nouveau modeset=0" | sudo tee -a /etc/modprobe.d/disable-nouveau.conf
sudo rmmod nouveau || true
sudo update-initramfs -u
tip
May need to disable the BIOS security boot, otherwise the driver will not be loaded.
# check the nvidia card
lspci | grep -i nvidia
# check the nvidia driver version
cat /proc/driver/nvidia/version
sudo apt install ubuntu-drivers-common
# check the nvidia driver
# for desktop
sudo ubuntu-drivers list
# for server
sudo ubuntu-drivers list --gpgpu
# install
# for desktop
sudo ubuntu-drivers install nvidia:xxx
# for server
sudo ubuntu-drivers install --gpgpu nvidia:xxx-server
sudo reboot
nvidia-smi
Cuda Toolkit
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
# Use 12.x
sudo apt-get -y install cuda-toolkit-12
~/.bashrc
export PATH=/usr/local/cuda-12.x/bin:$PATH
nvcc -V
Container Toolkit
The NVIDIA Container Toolkit is a collection of libraries and utilities enabling users to build and run GPU-accelerated containers.
tip
nvidia-container-runtime 和 nvidia-docker 均已停止维护,相关功能完全由 libnvidia-container 替代。
sudo apt-get update && sudo apt-get install -y --no-install-recommends \
curl \
gnupg2
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://mirrors.ustc.edu.cn/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://nvidia.github.io#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://mirrors.ustc.edu.cn#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt update && sudo apt install nvidia-container-toolkit
# configuring Docker
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
# test
docker info | grep Runtimes
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi