Setup Nvidia Drivers And NVIDIA Cuda Toolkit On Linux (PART-1)


A Complete Guide To Setup Nvidia Drivers And NVIDIA Cuda Toolkit On Fedora Linux



If you are struggling to setup NVIDIA drivers or NVIDIA Cuda environment in linux and does not find a complete solution then this guide is for you. This Guide have two parts; first, Installing NVIDIA drivers and second, setting up NVIDIA Cuda toolkit. This guide is tested on Fedora 34 and may or may not work on other Linux distros.

If you have already NVIDIA drivers installed then, you can skip to part 2 to setup NVIDIA CUDA toolkit. You can verify your NVIDIA driver installation by running the below command.

nvidia-smi

The output should be similar to the given below if you have valid Nvidia drivers installed.


Preliminaries

Update your system by running the following commands and reboot.

NOTE: below command will update and install some dependencies for  your system and reboot it.

sudo dnf update 
sudo dnf upgrade
sudo dnf install kernel-devel kernel-headers gcc make dkms acpid libglvnd-glx libglvnd-opengl libglvnd-devel pkgconfig
reboot


Step 1 ~ NVIDIA Drivers Install Guide

Check if your system have supported NVIDIA card by running below command in Linux terminal.

lspci |grep -E "VGA|3D"

# Example output
# 01:00.0 VGA compatible controller: NVIDIA Corporation TU106M [GeForce RTX 2060 Mobile] (rev a1)


Download and install the latest NVIDIA drivers from official website.

Go to the path you have downloaded the drivers file and run the below command.

chmod +x NVIDIA-Linux-*.run


Become a root user (important for next commands).

sudo -i

Append ‘blacklist nouveau’  to  'etc/modprobe.d/blacklist.co'

echo"blacklist nouveau">> /etc/modprobe.d/blacklist.conf


Append ‘rd.driver.blacklist=nouveau’ to end of ‘GRUB_CMDLINE_LINUX.

## Example row with Fedora 34 BTRFS #
GRUB_CMDLINE_LINUX="rhgb quiet rd.driver.blacklist=nouveau"## OR with LVM ##
GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora/swap rd.lvm.lv=fedora/root rhgb quiet rd.driver.blacklist=nouveau"


Update Grub2

## Fedora 34BIOS and UEFI ##
grub2-mkconfig -o /boot/grub2/grub.cfg
## Fedora 33/32/31/30BIOS ##
grub2-mkconfig -o /boot/grub2/grub.cfg

## UEFI ##
grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

 

Remove xorg-x11-drv-nouveau

## Fedora 34/33/32/31/30 ##
dnf remove xorg-x11-drv-nouveau


Generate initramfs

## Backup old initramfs nouveau image ##mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
 
## Create new initramfs image ##
dracut /boot/initramfs-$(uname -r).img $(uname -r)


Reboot to runlevel 3

NOTE: after reboot you will not have a GUI. We will install NVIDIA-Drivers  from tty command line after reboot. I highly recommend opening this guide on your mobile or other device so that you can easily follow along.

systemctl set-default multi-user.target
reboot


Installing Drivers

After reboot, you will land on tty, login by providing your username and password.
Next, go to the path where you have downloaded Nvidia drivers earlier and run the below command
.

sudo sh NVIDIA-Linux-*.run

# Example
# sudo sh NVIDIA-Linux-x86_64-465.31.run


Follow the installation prompts.
I have selected yes for all the prompts.






Restore to runlevel 5 (GUI Mode)

systemctl set-default graphical.target
reboot


Note:
If you still land on tty mode then run below command to start GUI mode

startx

You can verify your NVIDIA driver installation by running below command

nvidia-smi

The output should be similar to the given below if everything have been done smoothly.

If everything went smoothly then you should have successfully installed NVIDIA-DRIVERS.

Continue to Part-2 of this guide to install NVIDIA CUDA Toolkit.


Downloads Section:


Leave a comment below if you have any question or suggestions.

Happy Posting! See you in the next one.


Buy me a coffee!    or    Show your support!



Related Posts


Setup Pycharm IDE With Global Package Manager

Easy To Follow And Step-By-Step Guide To Setup Pycharm IDE With Global Packages Manager


By Yasir Hussain | Posted 3 months ago

Setup Pycharm IDE In Linux

Easy To Follow And Step-By-Step Guide To Setup JetBraine Pycharm IDE In Your Linux Distro


By Yasir Hussain | Posted 3 months ago

Setup IntelliJ IDE In Linux

Easy To Follow And Step-By-Step Guide To Setup JetBrains IntelliJ IDE In Your Linux Distro


By Yasir Hussain | Posted 3 months ago