- 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
- 7 Related Articles
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 various other computational tasks.
When using CUDA in an Ubuntu environment, it is crucial to check the CUDA version for the following reasons:
Driver Compatibility
CUDA requires a specific version of the NVIDIA driver to function correctly. If the versions are incompatible, CUDA may not work properly.
Library Compatibility
Libraries like TensorFlow and PyTorch require specific CUDA and cuDNN versions. It is essential to ensure that you have installed the appropriate version.
Preventing System Confusion
If multiple CUDA versions are installed on the system, it is necessary to identify which version is active and switch between versions as needed.
In this article, we will provide a clear explanation of how to check the CUDA version on Ubuntu.
2. How to Check the CUDA Version on Ubuntu
In an Ubuntu environment, you can check the CUDA version using the following methods:
Method 1: Check with the nvidia-smi Command (Easiest Method)
The NVIDIA driver includes a tool called nvidia-smi (NVIDIA System Management Interface) that allows you to check the status of your GPU.
Execution Command
nvidia-smiExample Output
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 530.41.03 Driver Version: 530.41.03 CUDA Version: 12.1 |
+-----------------------------------------------------------------------------+Key Points
- The
CUDA Version: 12.1displayed here represents the maximum CUDA version supported by the NVIDIA driver. - This may not always match the installed CUDA toolkit version, so it’s recommended to check using additional methods.
Method 2: Check with the nvcc -V Command (For Developers)
If CUDA is installed correctly, you can check the version of nvcc (the CUDA compiler).
Execution 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
- The part that says
release 12.1, V12.1.105indicates the installed CUDA toolkit version. - This may differ from the version displayed by
nvidia-smi, so be cautious.
Method 3: Check the version.txt File (Manual Verification)
If CUDA is installed in /usr/local/cuda, the version information is recorded in the version.txt file.
Execution Command
cat /usr/local/cuda/version.txtExample Output
CUDA Version 12.1.105Key Points
- This method is useful if the
nvcc -Vcommand is unavailable. - Ensure that
/usr/local/cudais correctly linked to the desired CUDA version.
3. How to Check the cuDNN Version
cuDNN (CUDA Deep Neural Network) is a library designed for deep learning and is used in combination with CUDA.
Along with checking the CUDA version, it is also important to verify the cuDNN version.
Method 1: Check the cudnn_version.h File
The cuDNN version is recorded in the header file cudnn_version.h.
Execution 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
- This output confirms that
cuDNN 8.9.1is installed. - Using the
grepcommand allows you to easily retrieve the cuDNN version information. - Since cuDNN must be compatible with CUDA, it is important to verify the correct combination of versions.
Method 2: Check with the dpkg Command (For Debian-based Linux)
On Ubuntu and other Debian-based Linux distributions, you can check the installed cuDNN version using the dpkg command.
Execution Command
dpkg -l | grep libcudnnExample Output
ii libcudnn8 8.9.1-1+cuda12.1 amd64 NVIDIA cuDNN LibraryKey Points
- The
libcudnn8 8.9.1-1+cuda12.1part confirms the installed cuDNN version (8.9.1). - The
cuda12.1part indicates the compatible CUDA version (12.1).
By using these methods, you can ensure that your CUDA environment is properly configured.

4. How to Handle Multiple Installed CUDA Versions
In an Ubuntu environment, multiple CUDA versions can be installed. However, this can sometimes lead to confusion regarding which version is currently active.
In such cases, you need to switch to the appropriate version.
Method 1: Switch Using update-alternatives
On Ubuntu, you can use update-alternatives to switch CUDA versions.
Check Current Settings
update-alternatives --query cudaSwitch CUDA Version
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
- Executing
update-alternatives --config cudawill display a list of available CUDA versions. - You can select the desired CUDA version by entering the corresponding number.
auto modeandmanual modeare available; choosemanual modeif you want to switch versions manually.
Method 2: Manually Set a Symbolic Link
You can also switch CUDA versions by modifying the symbolic link.
Check Existing Symbolic Link
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 Change
ls -l /usr/local/cudaKey Points
/usr/local/cudaserves as the default CUDA path. Changing this link switches the CUDA version.- By using the
ln -scommand, you can easily change the CUDA version without modifying system-wide configurations.
With these methods, you can efficiently manage multiple CUDA versions and ensure you are using the correct version for your needs.
5. Frequently Asked Questions (FAQ)
Here are some common questions related to checking the CUDA version. If you encounter any issues, refer to these solutions.
Q1: nvcc -V Command Not Found!
If the nvcc command is not found, CUDA may not be installed correctly, or its path is not set.
Solution 1: Check If CUDA Is Installed
ls /usr/local/cuda/Solution 2: Add nvcc to the Path
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATHAfter running these commands, try executing nvcc -V again to check if the version is displayed correctly.
Q2: Why Is the CUDA Version Displayed by nvidia-smi Different?
The CUDA version displayed by nvidia-smi represents the maximum CUDA version supported by the NVIDIA driver, not necessarily the installed CUDA toolkit version.
How to Check:
nvidia-smiExample Output:
CUDA Version: 12.1To check the actual installed CUDA version, use nvcc -V or check the version.txt file.
Q3: How to Check CUDA and cuDNN Compatibility?
The best way to check compatibility between CUDA and cuDNN is to refer to NVIDIA’s official support matrix.
Official Documentation:
Additionally, you can check the installed versions using the following commands:
Check CUDA Version
nvcc -VCheck cuDNN Version
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2By managing your environment correctly, you can avoid CUDA and cuDNN compatibility issues.
6. Summary
In this article, we explained how to check the CUDA version in an Ubuntu environment.
Let’s review the key points.
Ways to Check the CUDA Version
| Method | Command | Description |
|---|---|---|
nvidia-smi | nvidia-smi | Shows the CUDA version supported by the NVIDIA driver |
nvcc -V | nvcc -V | Shows the actual installed CUDA toolkit version |
version.txt | cat /usr/local/cuda/version.txt | Manually check the CUDA version |
Ways to Check the cuDNN Version
| Method | Command | Description |
|---|---|---|
cudnn_version.h | cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2 | Check the version from the header file |
dpkg Command | dpkg -l | grep libcudnn | Check the installed cuDNN version |
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 change the CUDA version |
Key Takeaways
- It is important to correctly identify the CUDA version
- Ensure compatibility between CUDA and cuDNN
- If using multiple CUDA versions, understand how to switch between them
By managing your environment properly, you can maximize the benefits of CUDA.
We hope this article helps you check the CUDA version in your Ubuntu environment.



