- 1 1. Introduction
- 2 2. How to Check the CUDA Version on Ubuntu
- 3 3. How to Check the cuDNN Version
- 4 4. How to Handle Multiple Installed CUDA Versions
- 5 5. Frequently Asked Questions (FAQ)
- 6 6. Summary
1. Introduction
CUDA (Compute Unified Device Architecture) is a parallel computing platform developed by NVIDIA that utilizes GPUs. It is widely used for machine learning, deep learning, 3D rendering, and many other computational workloads.
When using CUDA in an Ubuntu environment, it is important to check your CUDA version for the following reasons:
Driver Compatibility
CUDA supports only specific NVIDIA driver versions, and incompatibility can prevent CUDA from functioning correctly.
Library Compatibility
Libraries such as TensorFlow and PyTorch require specific versions of CUDA and cuDNN, so it is essential to verify that the correct versions are installed.
Avoiding Environment Conflicts
If multiple CUDA versions are installed on the system, you must know which version is currently active and switch between them as needed.
This guide clearly explains how to check the CUDA version on Ubuntu.
2. How to Check the CUDA Version on Ubuntu
In Ubuntu, you can check your CUDA version using the following methods.
Method 1: Check with nvidia-smi (Easiest Method)
The NVIDIA driver includes a tool called nvidia-smi (NVIDIA System Management Interface) that shows GPU information.
Command
nvidia-smiExample Output
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03 Driver Version: 530.41.03 CUDA Version: 12.1 |
+-----------------------------------------------------------------------------+Key Points
- The
CUDA Version: 12.1line shows the maximum CUDA version supported by the driver. - This may differ from the actual installed CUDA Toolkit version, so check the next methods as well.
Method 2: Check with nvcc -V (For Developers)
If CUDA is properly installed, you can check the version of nvcc, the CUDA compiler.
Command
nvcc -VExample Output
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Sun_Jul_30_19:09:40_PDT_2023
Cuda compilation tools, release 12.1, V12.1.105Key Points
release 12.1, V12.1.105→ This indicates the installed CUDA Toolkit version.- It may not match the version shown by
nvidia-smi.
Method 3: Check version.txt (Manual Check)
If CUDA is installed under /usr/local/cuda, the file version.txt contains version information.
Command
cat /usr/local/cuda/version.txtExample Output
CUDA Version 12.1.105Key Points
- Useful when
nvcc -Vis unavailable. - You must ensure that
/usr/local/cudais correctly symlinked.
3. How to Check the cuDNN Version
cuDNN (CUDA Deep Neural Network) is a deep learning library used with CUDA.
It is important to check the cuDNN version along with CUDA.
Method 1: Check cudnn_version.h
The cuDNN version is stored in the header file cudnn_version.h.
Command
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2Example Output
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 9
#define CUDNN_PATCHLEVEL 1Key Points
- Indicates that
cuDNN 8.9.1is installed. - The
grepcommand helps extract version info easily. - cuDNN and CUDA must be compatible; verify the correct pairing.
Method 2: Check with dpkg (Debian-Based Linux Only)
On Debian-based systems like Ubuntu, you can check installed cuDNN packages with dpkg.
Command
dpkg -l | grep libcudnnExample Output
ii libcudnn8 8.9.1-1+cuda12.1 amd64 NVIDIA cuDNN LibraryKey Points
- The cuDNN version (8.9.1) is shown in the package name.
cuda12.1indicates the compatible CUDA version.
Use these methods to ensure your CUDA environment is configured correctly.

4. How to Handle Multiple Installed CUDA Versions
In Ubuntu, it is possible to install multiple versions of CUDA. However, this may cause confusion about which version is currently active.
In such cases, you must switch to the correct version manually.
Method 1: Switch Versions Using update-alternatives
Ubuntu allows you to switch between CUDA versions using the update-alternatives tool.
Check Current Settings
update-alternatives --query cudaSwitch Versions
sudo update-alternatives --config cudaExample Output
There are 3 choices for the alternative cuda (providing /usr/local/cuda).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/local/cuda-11.8 100 auto mode
1 /usr/local/cuda-10.2 50 manual mode
2 /usr/local/cuda-11.8 100 manual mode
3 /usr/local/cuda-12.1 110 manual mode
Press <enter> to keep the current choice[*], or type selection number:Key Points
- Running
update-alternatives --config cudadisplays all available CUDA versions. - You can select the version to use by entering the corresponding number.
auto modeandmanual modeare available; choosemanual modefor manual switching.
Method 2: Manually Configure Symbolic Links
You can also activate a specific CUDA version by manually adjusting symbolic links.
Check Existing Symlink
ls -l /usr/local/cudaExample Output
lrwxrwxrwx 1 root root 20 Feb 1 12:34 /usr/local/cuda -> /usr/local/cuda-11.8Change CUDA Version
sudo rm /usr/local/cuda
sudo ln -s /usr/local/cuda-12.1 /usr/local/cudaVerify
ls -l /usr/local/cudaKey Points
/usr/local/cudais used as the default CUDA path, so updating this link switches the active version.- Using
ln -smakes switching between versions easy.
By using these methods, you can manage multiple CUDA installations and ensure the correct version is active.
5. Frequently Asked Questions (FAQ)
This section summarizes common issues related to checking CUDA versions. Use it for troubleshooting.
Q1: nvcc -V is not found!
If the nvcc command is missing, the CUDA path may not be set.
Solution 1: Check if CUDA is installed
ls /usr/local/cuda/Solution 2: Add nvcc to PATH
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATHAfter this, run nvcc -V again to confirm it works.
Q2: Why is the CUDA version shown by nvidia-smi different?
The CUDA version shown by nvidia-smi represents the maximum CUDA version supported by the NVIDIA driver.
Check Example:
nvidia-smiExample Output:
CUDA Version: 12.1However, this does not indicate the installed CUDA Toolkit version. Use nvcc -V or version.txt to verify the actual installed version.
Q3: How do I check CUDA and cuDNN compatibility?
The most accurate way is to refer to NVIDIA’s official support matrix.
Official Site:
You should also confirm compatibility by checking the installed versions:
Check CUDA Version
nvcc -VCheck cuDNN Version
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2By managing these versions appropriately, you can avoid issues related to CUDA and cuDNN.
6. Summary
This article explained how to check the CUDA version in an Ubuntu environment.
Let’s review the key points.
How to Check CUDA Versions
| Method | Command | Description |
|---|---|---|
nvidia-smi | nvidia-smi | Shows the CUDA version supported by the driver |
nvcc -V | nvcc -V | Shows the installed CUDA Toolkit version |
version.txt | cat /usr/local/cuda/version.txt | Manually check the installed CUDA version |
How to Check cuDNN
| Method | Command | Description |
|---|---|---|
cudnn_version.h | cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2 | Check version from the header file |
dpkg | dpkg -l | grep libcudnn | Check installed cuDNN packages |
How to Switch CUDA Versions
| Method | Command | Description |
|---|---|---|
update-alternatives | sudo update-alternatives --config cuda | Switch between multiple CUDA versions |
| Symbolic Link | sudo ln -s /usr/local/cuda-XX.X /usr/local/cuda | Manually switch CUDA versions |
Key Takeaways
- Always verify your CUDA version before development
- Check compatibility between CUDA and cuDNN
- Understand how to switch versions when multiple CUDA installations exist
By properly managing your environment, you can maximize the performance and stability of CUDA.
We hope this guide helps you verify CUDA versions effectively on Ubuntu.



