How to use GPU Nvidia on Ubuntu

Tue, Aug 22, 2023

Read in 2 minutes

It's the drivers, and it's fast!

How to use GPU Nvidia on Ubuntu

Installing CUDA Drivers on Ubuntu

Introduction to CUDA and its Applications

CUDA (Compute Unified Device Architecture) is a parallel computing platform and programming model developed by NVIDIA. It empowers developers to tap into the immense computational power of NVIDIA GPUs for accelerating a wide range of tasks.

With CUDA, tasks that demand intensive parallel processing, such as deep learning, scientific simulations, and data analysis, can be performed dramatically faster. By leveraging the thousands of cores within a GPU, CUDA has revolutionized fields that require heavy computational lifting, making it a go-to solution for researchers, developers, and data scientists.

We’re going to be following these steps:

  1. Ensure you have a Nvidia GPU available.
  2. Update your system
  3. Install latest nvidia drivers
  4. Disable default ubuntu drivers
  5. Install CUDA apps
  6. Verify installation

Very easy way to keep up with new releases.

Follow these steps to install CUDA drivers on the latest Ubuntu:

  1. Check GPU Compatibility: Ensure your GPU is compatible with the CUDA version you intend to install. Refer to NVIDIA’s official documentation for compatibility details.

    Open up a terminal Ctrl+Alt+T and type

    lspci | grep -i nvidia
    

    The output should be shomething like this:

    nvidia checking

    If there is no output, then you don’t have a Nvidia GPU. Sorry.

  2. Update System:

    sudo apt update
    sudo apt upgrade -y
    
  3. Nvidia drivers: Instructions from the official nvidia driver installation guide for ubuntu 22.xx found here.

    sudo apt install linux-headers-$(uname -r)
    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 update
    sudo apt install cuda-drivers
    
  4. Disable default driver: By disabling the default Nvidia driver from Canonical you will save a lot of trouble.

    echo -e "blacklist nouveau\noptions nouveau modeset=0" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
    sudo update-initramfs -u
    
  5. Reboot: Reboot your system to apply the Nouveau driver changes.

  6. CUDA package installation: With all the steps above, you can safely copy&paste this code block.

    sudo apt install cuda
    
    Codeblock from deb&network installation on Ubuntu 22.04 from Nvidia here.
  7. Reboot: Reboot your system to get your CUDA up and running!

  8. Verifications: The best way to check everything went well is to check nvidia-smi

    nvidia-smi
    

    The output should be like this, and with DRIVER VERSION and CUDA VERSION.

    nvidia-smi

The package manager will automatically update everything. True Gold.

This is a wrap-up of the official Nvidia CUDA installation Guide for Linux, found here