How to Install NVIDIA CUDA Toolkit on Ubuntu 22.04?
We’ve got you covered! If you are about to dive into a world of machine learning, AI development, or any form of GPU-accelerated computing, considering and installing the NVIDIA CUDA Toolkit should be one of the first tasks on your to-do list. You can consider this a quick instruction for installing the CUDA Toolkit on Ubuntu 22.04 as well as some important suggestions to get you and your system set up and running as soon as possible.
What is CUDA?
CUDA (Compute Unified Device Architecture) is a parallel computing platform and programming model developed by NVIDIA. CUDA enables developers to use a parallel computing approach to general-purpose computing on graphics processing units (GPGPU) and speed up workloads versus processing on a CPU.
Hence, its applications include:
- Deep Learning and Neural Networks
- Scientific Simulations
- Big Data Analytics
- Video Processing
Prerequisites
Before we install CUDA on Ubuntu 22.04, here’s what you need:
- A CUDA-capable NVIDIA GPU (check list at official CUDA GPUs)
- Ubuntu 22.04 LTS (clean installation preferred)
- NVIDIA driver version 535 or newer
- Internet access to download installation packages
- Basic knowledge of using the Linux terminal
Step-by-Step: Install NVIDIA CUDA Toolkit on Ubuntu 22.04
Step 1: Remove Conflicting Packages
To avoid any issues during installation, remove old or conflicting NVIDIA and CUDA packages:
sudo apt-get --purge remove '*cublas*' 'cuda*' 'nsight*' 'nvidia*' sudo apt-get autoremove -y sudo apt-get clean
It ensures that the new CUDA installation starts from a clean slate.
Step 2: Install the Appropriate NVIDIA Driver
First, add the graphics driver PPA and install the latest driver:
sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt update sudo apt install nvidia-driver-535 -y
Reboot your machine:
sudo reboot
After rebooting, confirm installation with:
nvidia-smi
You should see your GPU listed along with driver information.
Step 3: Download CUDA Toolkit from NVIDIA
Visit the official NVIDIA CUDA Toolkit download page and select:
- OS: Linux
- Architecture: x86_64
- Distribution: Ubuntu
- Version: 22.04
- Installer Type: deb (local)
Then, run the following:
wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda-repo-ubuntu2204-12-2-local_12.2.0-535.54.03-1_amd64.deb sudo dpkg -i cuda-repo-ubuntu2204-12-2-local_12.2.0-535.54.03-1_amd64.deb
Step 4: Add GPG Key and Update Repositories
To authenticate the repository:
sudo cp /var/cuda-repo-ubuntu2204-12-2-local/cuda-216F19BD-keyring.gpg /usr/share/keyrings/ sudo apt-get update
Step 5: Install the CUDA Toolkit
sudo apt-get -y install cuda
It installs CUDA, cuDNN, and other supporting packages.
Step 6: Set Environment Variables
Add the following lines to your .bashrc file to make the CUDA Toolkit available to your shell:
echo 'export PATH=/usr/local/cuda-12.2/bin:$PATH' >> ~/.bashrc echo 'export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc
You can also update /etc/environment for system-wide access.
Verify Installation
Check CUDA Compiler (nvcc)
nvcc --version
Expected output includes CUDA release version and build info.
Confirm GPU Status
nvidia-smi
It shows active GPU processes, memory usage, and driver versions.
Run CUDA Sample Projects
git clone https://github.com/NVIDIA/cuda-samples.git cd cuda-samples/Samples/1_Utilities/deviceQuery make ./deviceQuery
If everything works, you should see the output ending with Result = PASS.
Optional: Install CUDA via Conda
Using Conda is a great way to isolate your CUDA environment:
conda create -n cuda-env conda activate cuda-env conda install -c nvidia cuda
Use this approach if you want to avoid modifying your system-wide configuration.
In Conclusion
Installing the NVIDIA CUDA Toolkit on Ubuntu 22.04 enables you to utilize the power of GPU computing, for example, training your next deep learning model, running a computationally heavy simulation, or processing large datasets.
The most important point is to take your time, to take this guide in sequence, step by step and check each step before going to the next one. After you have made it through the installation and checked if CUDA is installed properly, you can begin developing high-performance GPU-accelerated applications.
Frequently Asked Questions (FAQs)
1. What is the latest CUDA version for Ubuntu 22.04?
Currently, CUDA 12.8 is the latest stable release for Ubuntu 22.04.
2. Can I install multiple versions of CUDA?
Yes, multiple instances of CUDA can be installed. However, be sure to manage environment variables carefully to avoid version conflicts.
3. Should I use the .run file instead?
The .run file offers more customization but can be harder to manage. The .deb (local) method is safer and more user-friendly.
4. What if nvidia-smi doesn’t show the GPU?
Double-check your NVIDIA driver installation and ensure Secure Boot is disabled (BIOS setting).
5. Do I need cuDNN?
If you want to use TensorFlow or PyTorch with CUDA, you should also install cuDNN for optimal performance.