Linux & NVIDIA Drivers
Install and configure NVIDIA GPU drivers on your Linux instances.
Prerequisites
Before you begin, make sure you have:
- A running Linux instance with an NVIDIA GPU on MegaTech
- SSH access to your instance (see How to SSH into your instance)
- Root or sudo privileges on your instance
- Basic familiarity with Linux command line
Distribution-Specific Instructions
Select your Linux distribution for specific installation instructions:
Ubuntu 20.04/22.04
- Update your system:
sudo apt update && sudo apt upgrade -y
- Install required packages:
sudo apt install -y build-essential gcc make linux-headers-$(uname -r)
- Add the NVIDIA repository (optional but recommended for latest drivers):
sudo add-apt-repository ppa:graphics-drivers/ppa && sudo apt update
- Install the NVIDIA drivers:
sudo apt install -y nvidia-driver-535
- Reboot your system:
sudo reboot
CentOS/RHEL 8/9
- Update your system:
sudo dnf update -y
- Install required packages:
sudo dnf install -y kernel-devel kernel-headers gcc make dkms
- Add the NVIDIA repository:
sudo dnf config-manager --add-repo=https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
- Install the NVIDIA drivers:
sudo dnf install -y nvidia-driver-latest-dkms
- Reboot your system:
sudo reboot
Arch Linux
- Update your system:
sudo pacman -Syu
- Install required packages:
sudo pacman -S --needed linux-headers base-devel
- Install the NVIDIA drivers:
sudo pacman -S nvidia
- Reboot your system:
sudo reboot
Verify Installation
After installing the drivers and rebooting, verify that the drivers are working correctly:
Check driver installation
nvidia-smi
This command should display information about your GPU(s), including the driver version, GPU model, and utilization. If you see this output, the drivers are installed correctly.
Check CUDA installation (if installed)
nvcc --version
This command displays the CUDA compiler version if CUDA is installed.
Installing CUDA (Optional)
If you plan to use your GPU for machine learning or CUDA-accelerated applications, you'll need to install the CUDA Toolkit:
Ubuntu
# Add CUDA repository
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
# Install CUDA
sudo apt-get install -y cuda-toolkit-12-0
# Add CUDA to your PATH (add to ~/.bashrc)
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
CentOS/RHEL
# Install CUDA
sudo dnf install -y cuda
# Add CUDA to your PATH (add to ~/.bashrc)
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
Arch Linux
# Install CUDA
sudo pacman -S cuda
# Add CUDA to your PATH (add to ~/.bashrc)
echo 'export PATH=/opt/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/opt/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
Troubleshooting
nvidia-smi command not found
This usually indicates that the NVIDIA drivers are not installed correctly. Try the following:
- Make sure you've rebooted after installing the drivers
- Check if the NVIDIA kernel modules are loaded:
lsmod | grep nvidia
- If no modules are shown, try loading them manually:
sudo modprobe nvidia
- If you get errors, check your kernel logs:
dmesg | grep -i nvidia
Failed to initialize NVML
This error may appear when running nvidia-smi
. It usually indicates a driver-kernel mismatch. Try these steps:
- Reboot your system
- If that doesn't work, reinstall the drivers
- Make sure you're not using Wayland as your display server (some NVIDIA drivers have issues with Wayland)
Black screen after reboot
If your screen goes black after installing drivers and rebooting, it's likely a graphics issue. SSH into your instance and:
- Remove the drivers:
sudo apt purge nvidia*
(Ubuntu) orsudo dnf remove nvidia*
(CentOS) - Try installing a different driver version
- Check if your GPU is compatible with the driver version you're installing
Last updated 8 months ago
Was this helpful?