Installing NVIDIA GPU Drivers on Ubuntu
Identify Your GPU
Open a terminal and run one of the following commands:
lspci | grep -i vga
# or
lspci | grep -i nvidia
The output will include your GPU model. For example:
01:00.0 VGA compatible controller: NVIDIA Corporation TU116 [GeForce GTX 1660 SUPER] (rev a1)
Download the Correct Driver
Visit the NVIDIA driver download page. Select your GPU model, operating system (Linux 64-bit), and Ubuntu version to get the appropriate .run file.
Prepare the System
Update packages and install build tools:
sudo apt update
sudo apt upgrade -y
sudo apt install -y gcc g++ make
Disable the Nouveau Driver
Create or edit the blacklist configuraton:
sudo nano /etc/modprobe.d/blacklist-nouveau.conf
Add these lines:
blacklist nouveau
options nouveau modeset=0
Regenerate the initramfs and reboot:
sudo update-initramfs -u
sudo reboot
Install the NVIDIA Driver
After rebooting, switch to a TTY console (e.g., press Ctrl+Alt+F2) and log in.
Stop the display manager (use gdm3 if you're on GNOME):
sudo systemctl stop lightdm
# or
sudo systemctl stop gdm3
Navigate to the directory containing the downloaded .run file, make it executable, and run it:
chmod +x NVIDIA-Linux-x86_64-*.run
sudo ./NVIDIA-Linux-x86_64-*.run
Accept the license and follow prompts. Use default options unless you have specific requirements.
Verify Installation
Reboot the system:
sudo reboot
After login, confirm the driver is active:
nvidia-smi
A successful output shows GPU details, driver version, and CUDA version.
Fix Driver Issues After Kernel Updates
If nvidia-smi fails with a communication error after a system update, the kernel module may be incompatible with the new kernel.
Install DKMS to automatically rebuild drivers for new kernels:
sudo apt install -y dkms
Rebuild the NVIDIA modules for the current kernel:
# Replace <version> with your actual driver version, e.g., 550.54.14
sudo dkms install -m nvidia -v <version>
Then reload the modules or reboot:
sudo modprobe nvidia
# or
sudo reboot
Run nvidia-smi again to confirm functionality.