CUDA Installation

Dummy proof guide to install CUDA on anything (with a NVIDIA gpu).

Table of contents

  1. About
  2. Linux Installation
    1. Purge/Remove all existing references to CUDA/NVIDIA, if they exist.
    2. Install specific NVIDIA driver version needed for the desired CUDA toolkit version.
    3. Check if driver was installed correctly.
    4. Fetch the key and repositories from NVIDIA directly.
    5. Install CUDA.
    6. Update the enviornment variables in your .bashrc file.
    7. Check if CUDA was installed correctly.

About

I got frustrated with CUDA install guides, so I made this one for my own reference.


Linux Installation

Working as of 11/13/2024. :)

Purge/Remove all existing references to CUDA/NVIDIA, if they exist.

sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /usr/loca/cuda*

Reboot machine.

Install specific NVIDIA driver version needed for the desired CUDA toolkit version.

Check the CUDA compatibility list and visit the NVIDIA developer repositories page to ensure the version of CUDA is correct for your Ubuntu and Driver version.

CUDA Compatibility List: https://docs.nvidia.com/deploy/cuda-compatibility/ NVIDIA Developer Repositories (apt-key : 3bf863cc.pub)

  • Ubuntu 22.04: https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/
  • Ubuntu 24.04: https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update

sudo apt-get install -y nvidia-driver-{VERSION_NUMBER}

Reboot machine.

Check if driver was installed correctly.

nvidia-smi

Fetch the key and repositories from NVIDIA directly.

sudo apt-get adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /"

Install CUDA.

sudo apt-get update
sudo apt-get install -y cuda-toolkit-{VERSION}

Example: sudo apt-get install -y cuda-toolkit-12-1

Update the enviornment variables in your .bashrc file.

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

Check if CUDA was installed correctly.

nvcc --version