Installing NVIDIA GPU Driver on Ubuntu
This is a method to make sure that a recommended driver of your NVIDIA GPU is installed in your Ubuntu computer:
Step 1: Check for NVIDIA GPU availability and driver information:
nvidia-smi
If this command returns the driver information of your NVIDIA GPU, you can skip the next steps.
Step 2:
Check for Existing NVIDIA Drivers: If you’ve tried installing drivers before and had issues, it’s a good idea to purge any existing NVIDIA packages to avoid conflicts.
sudo apt-get remove –purge ‘^nvidia-.‘ ‘^libnvidia-.‘ ‘^cuda-.*’
sudo apt autoremove
sudo apt clean
Step 3:
sudo apt update
sudo apt upgrade
Step 4:
Install Essential Build Tools: These are needed for kernel module compilation (DKMS).
sudo apt install build-essential linux-headers-$(uname -r)
Step 5:
List Available Drivers:
ubuntu-drivers devices
This command will scan your hardware and list the available NVIDIA drivers for your specific GPU, indicating which one is recommended. You’ll see output like:
driver : nvidia-driver-550 – recommended
Step 6:
Install the Recommended Driver:
sudo ubuntu-drivers autoinstall
This command will automatically install the NVIDIA driver version that ubuntu-drivers devices marked as recommended.
Step 7:
Reboot the computer:
sudo reboot
Step 8:
Verify Installation:
nvidia-smi
You should see detailed information about your NVIDIA GPU, driver version, CUDA version, and GPU utilization. If this command returns information, your drivers are successfully installed.
Step 9:
If you have NVIDIA GPU:
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg –dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed ‘s#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g’ | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit