Setup NVIDIA Drivers + CUDA + PyTorch on Ubuntu 22.04

Jessie Li 0 Reputation points
2025-05-27T10:29:32.5866667+00:00

I am trying to Setup NVIDIA Drivers + CUDA + PyTorch on Ubuntu 22.04 but failed - can I get a step by step guide to debug?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Alex Burlachenko 9,780 Reputation points
    2025-05-27T11:49:44.03+00:00

    Hi Jessie Li,

    don’t worry, we’ll figure it out step by step. first off, thanks for throwing this question out there ubuntu 22.04 is a solid choice, but yeah, the driver setup can get messy if things don’t line up just right.

    ok, let’s start fresh. u gotta make sure u have the right nvidia drivers installed. open up a terminal and run sudo apt update to get everything up to date. then, check if u have any old drivers hanging around with sudo apt purge nvidia* this cleans up any leftovers that might cause trouble.

    next, u want add the official nvidia repo to ur system. run sudo add-apt-repository ppa:graphics-drivers/ppa and hit enter. then sudo apt update again. now, u can install the latest drivers with sudo apt install nvidia-driver-535 (or whatever version is current—check nvidia’s site for the latest stable one nvidia driver docs). reboot after this with sudo reboot, and when u come back, run nvidia-smi to see if the drivers are working. if u see a table with gpu info, u’re golden ;)

    now for cuda. u can grab it straight from nvidia’s site cuda toolkit docs. download the runfile for ubuntu 22.04 and run it with sudo sh cuda_*.run. make sure u don’t install the bundled drivers just the toolkit and maybe the samples if u want them. after it’s done, add cuda to ur path by editing ~/.bashrc and adding export PATH=/usr/local/cuda/bin:$PATH and export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH. then run source ~/.bashrc to apply it. check if cuda works with nvcc --version it should spit out the version number.

    finally, pytorch. this part’s easier )) head over to pytorch’s official site and grab the command for linux with cuda support. usually, it’s something like pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118. make sure the cuda version matches what u installed earlier. after that, fire up python and try import torch followed by torch.cuda.is_available(). if it says True, congrats u did it )))

    if anything fails along the way, check the error messages carefully.

    LMK if some my advise is help.

    Alex
    and "yes" if you would follow me at Q&A - personaly thx.
    P.S. If my answer help to you, please Accept my answer
    PPS That is my Answer and not a Comment
    https://ctrlaltdel.blog/
    
    0 comments No comments

  2. Nikhil Duserla 7,935 Reputation points Microsoft External Staff Moderator
    2025-05-28T14:08:01.8666667+00:00

    Hello @Jessie Li,

    You must disable Secure Boot on the Linux VM after installing the signed kernel module for use with GRID.

    The GRID driver redistributed by Azure does not work on many non-NV-series VMs (such as NC, NCv2, NCv3, ND, and NDv2-series VMs), but it does work on NCasT4v3-series.For more information about specific vGPU and driver branch versions, see the NVIDIA website.

    GRID Driver 17.3 currently only supports NCasT4_v3-series VMs. To use this driver, manually download and install GRID Driver 17.3.

    For more detailed information please reach out Microsoft official link- https://learn.microsoft.com/en-us/azure/virtual-machines/linux/n-series-driver-setup#nvidia-grid-drivers

    Here is the clear document Installing the NVIDIA Driver on an Azure VM- https://forums.developer.nvidia.com/t/installing-nvidia-drivers-cuda-on-azure-nvadsa10-v5-vm-ubuntu-22-04/321128/3#p-1604105-installing-the-nvidia-driver-on-an-azure-vm-1

    If you have any further queries, do let us know.

    If you are still running into this issue, please let us know in the comments so we can continue to investigate this. If the problem has been resolved, please take a moment to accept answers.

    Thank you for helping to improve Microsoft Q&A!

    User's image


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.