How to Check for NVIDIA GPU and Set It Up in Ubuntu

If you want to run deep learning models or GPU-accelerated tasks on Ubuntu, having an NVIDIA GPU and the correct drivers is essential. This guide will help you check if a GPU is available and set it up properly for PyTorch.

1 Check if your system has an NVIDIA GPU

Open a terminal and run:

lspci | grep -i nvidia
If output appears, your system has an NVIDIA GPU.
0000:01:00.0 3D controller: NVIDIA Corporation GP107M [GeForce MX350] (rev a1)
If no output, your system either doesn't have a GPU or it's disabled in BIOS.
💡 Tip: Take note of your GPU model. You'll need it to choose the correct driver.

2 Check if NVIDIA drivers are installed

Run:

nvidia-smi
If working, you will see a table with GPU info, driver version, and CUDA version:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 580.95.05   Driver Version: 580.95.05   CUDA Version: 13.0       |
| GPU  Name                 Memory-Usage | GPU-Util  Compute M.               |
| 0   NVIDIA GeForce MX350   5MiB / 2048MiB | 0%                           |
+-----------------------------------------------------------------------------+
If it fails, the driver is not installed or not loaded.

3 Find the recommended NVIDIA driver

Run:

ubuntu-drivers devices

Example output:

driver   : nvidia-driver-580 - distro non-free recommended
⚠️ Important: Always install the recommended driver for your GPU.

4 Install the NVIDIA driver

sudo apt update
sudo apt install nvidia-driver-580

Then reboot your system:

sudo reboot

5 Verify the driver and CUDA

After reboot, check again:

nvidia-smi

You should now see your GPU detected along with driver and CUDA version.

6 Install PyTorch with GPU support

Now that your GPU is working, install PyTorch. Make sure to match the CUDA version from nvidia-smi.

Example for CUDA 13.0:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130

7 Verify PyTorch GPU access

Open Python:

import torch

print("CUDA Version:", torch.version.cuda)
print("GPU Available:", torch.cuda.is_available())
print("GPU Name:", torch.cuda.get_device_name(0))

Expected output:

CUDA Version: 13.0
GPU Available: True
GPU Name: NVIDIA GeForce MX350
💡 Tip: If torch.cuda.is_available() returns False, check that the driver is loaded properly and your CUDA version matches.

8 CPU-only fallback

If you don't have a GPU or cannot install drivers:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

You can still run PyTorch on CPU, but it will be slower.

Summary

  1. Check for GPU: lspci | grep -i nvidia
  2. Check driver: nvidia-smi
  3. Install recommended driver: ubuntu-drivers devicessudo apt install <driver>
  4. Verify GPU access
  5. Install PyTorch for GPU (match CUDA version) or CPU-only

With this setup, your Ubuntu machine is ready for GPU-accelerated deep learning.

Comments

Popular posts from this blog

Use the Google Custom Search JSON API to retrieve images

Terminal commands relared to files in the Ubuntu

Laravel Best Practices: Building Robust and Maintainable Applications