How to Install Nvidia CUDA and cuDNN on Ubuntu 22.04

Step-by-step guide on installing Nvidia CUDA and cuDNN on Ubuntu 22.04 for efficient GPU acceleration. Maximize your system's performance for deep learning and AI applications with these essential tools and configurations.

Ubuntu 22.04 is a popular operating system choice for developers and enthusiasts, known for its stability and versatility. In this article, we will guide you through the process of installing Nvidia CUDA and cuDNN on Ubuntu 22.04. These powerful tools are essential for accelerating deep learning and GPU-accelerated computing tasks. By following this step-by-step guide, you will be able to harness the full potential of your Nvidia GPU.


Before we begin, ensure that your system meets the following prerequisites:

  • Ubuntu 22.04 installed
  • Nvidia GPU with CUDA support
  • Internet connection

Installing Nvidia CUDA

Step 1: Checking compatibility

First, check the compatibility of your Nvidia GPU with CUDA by referring to the official CUDA documentation. Ensure that your GPU is supported by the CUDA version you plan to install.

Step 2: Downloading CUDA Toolkit

Go to the official Nvidia CUDA Toolkit website and download the appropriate CUDA Toolkit version for Ubuntu 22.04. Choose the runfile (local) installation option.

Step 3: Installing CUDA Toolkit

Once the download is complete, open a terminal and navigate to the directory where the CUDA Toolkit installer is located. Run the following command to make the installer executable:

chmod +x cuda_*.run

Next, initiate the installation process by executing the installer:

sudo ./cuda_*.run

Follow the on-screen prompts and accept the license agreement. During the installation, you will be prompted to choose the installation options. It is recommended to select the default options unless you have specific requirements.

Step 4: Setting up environment variables

To use CUDA, you need to set up the environment variables. Open the terminal and run the following command:

echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

Step 5: Verifying the installation

To verify the installation, run the following command in the terminal:

nvcc --version

If the installation was successful, you should see the CUDA version information.

Installing cuDNN

Step 1: Downloading cuDNN

Visit the Nvidia Developer website and download the cuDNN library corresponding to the CUDA version you installed. Make sure to choose the cuDNN library that matches your Ubuntu 22.04 architecture.

Step 2: Extracting and copying files

Once the download is complete, open a terminal and navigate to the directory where the cuDNN library file is located. Extract the files using the following command:

tar -xzvf cudnn-*.tgz

Copy the extracted files to the CUDA Toolkit directory:

sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

Step 3: Configuring cuDNN

To configure cuDNN, open the terminal and run the following commands:

sudo ldconfig

Step 4: Verifying the installation

To verify the cuDNN installation, compile and run a sample cuDNN program. Refer to the cuDNN documentation for sample code and instructions.


Congratulations! You have successfully installed Nvidia CUDA and cuDNN on Ubuntu 22.04. You are now ready to leverage the power of GPU acceleration for deep learning and other computationally intensive tasks. Enjoy the enhanced performance and efficiency that Nvidia CUDA and cuDNN bring to your projects.

Remember to keep your Nvidia CUDA and cuDNN versions up to date to benefit from the latest features and optimizations.

Must Read

Related Articles