This guide walks you through the steps to install NVIDIA's CUDA toolkit on Ubuntu 22.04. CUDA allows you to harness the power of NVIDIA GPUs for computing-intensive tasks like machine learning, simulations, and more.
- A machine running Ubuntu 22.04
- A CUDA-compatible NVIDIA GPU
Update and upgrade your system packages:
sudo apt update && sudo apt upgrade
Identify and install the recommended NVIDIA driver for your GPU:
sudo ubuntu-drivers devices
sudo apt install nvidia-driver-<version> # Replace <version> with your recommended driver
Reboot your machine:
sudo reboot
To verify that the NVIDIA driver is installed correctly, run the following command:
nvidia-smi
You should see an output similar to the following, which indicates that the driver is installed and the GPU is recognized:
- Download and install the CUDA repository package:
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 sudo apt-get install -y cuda
Update your environment variables by adding the following lines to your .bashrc
:
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Reload the .bashrc
file:
source ~/.bashrc
Reboot your machine:
sudo reboot
After installation, check if CUDA was installed correctly:
nvcc -V
For detailed instructions, see the official NVIDIA CUDA Toolkit Documentation.