Installing NVIDIA drivers on Linux is always difficult. This is the step by step guide for installing NVIDIA drivers on Kali Linux. I used these steps to install my NVIDIA GTX1050Ti drivers on Kali Linux. This processes is tested on Kali Linux 2019.4 Gnome 64-Bit.

Step 1: Install the Kali Linux on hard drive. Restart computer after the installation process completed.

Setp 2: Now you will see the Kali Linux Grub Bootloader with a blue screen.  From the GRUB loader select Kali Linux and press E. Now navigate the cursor to the row starting with Linux, then at the end of the row replace “quiet splash” with “nouveau.modeset=0” (without quote marks). Then press F10. These steps will fix boot loading and freezing issue in Kali Linux. Now Kali Linux will boot normally. Instructions with image is shown below.

Kali Linux Boot Screen

From the GRUB loader select Kali Linux and press E.

quiet splash Kali linux

Now navigate the cursor to the row starting with Linux, then at the end of the row replace “quiet splash” with “nouveau.modeset=0” (without quote marks).

Fix Kali Linux booting problem with nouveau.modeset=0

Then press F10.

Step 3: After Kali Linux booted up run this command below.

apt-get update
apt-get upgrade
apt-get dist-upgrade

After that follow the steps below to install Nvidia drivers:

Step 4: Before we begin, you’ll need to make sure you have the kernel headers for your currently active kernel, in order to build the NVIDIA driver kernel modules type:

apt install linux-headers-$(uname -r)

This will automatically resolve the kernel headers package required for the kernel you are currently using.
Step 5: Disable nouveau

echo -e "blacklist nouveau\noptions nouveau modeset=0\nalias nouveau off" > /etc/modprobe.d/blacklist-nouveau.conf
update-initramfs -u && reboot

Now system will reboot and nouveau should be disabled.

Step 6: Verify if nouveau is disabled:

lsmod |grep -i nouveau

If this command shows nothing, that means nouveau has successfully disabled.

Step 7: Install Nvidia driver from kali repository:

apt-get install nvidia-driver nvidia-xconfig

Step 8: Find the bus id of Nvidia card:

nvidia-xconfig --query-gpu-info | grep 'BusID : ' | cut -d ' ' -f6

>>My result: PCI:1:0:0
>>PCI:1:0:0 This is our Bus ID.

Step 9: Now we will create /etc/X11/xorg.conf file with this bus ID according to the Nvidia’s guide.
You can download the xorg.conf file from here and edit the BusID value with your Bus ID using any text editor. Then keep the xorg.conf file in /etc/X11/
Or you can make a xorg.conf file using the text below.

Section "ServerLayout"
    Identifier "layout"
    Screen 0 "nvidia"
    Inactive "intel"

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1:0:0"

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    Option "AllowEmptyInitialConfiguration"

Section "Device"
    Identifier "intel"
    Driver "modesetting"

Section "Screen"
    Identifier "intel"
    Device "intel"

>>Replace the BusID value with your Bus ID and save it to /etc/X11/xorg.conf

Step 10: Now we have to create some scripts according to our display manager. Since I’m using default Kali Linux display manager which is GDM, thus I created two optimus.desktop files in directory mentioned below
with the following content:

[Desktop Entry]
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"

You can also download the optimus.desktop file for GDM and copy that to both directory /usr/share/gdm/greeter/autostart/ and /etc/xdg/autostart/

Step 11: Now reboot your computer and you should be using Nvidia Driver. Verify if everything is working perfectly by using the command below:

apt-get install mesa-utils
glxinfo | grep -i "direct rendering"

>>Result Should be “direct rendering: Yes”

Installing Nvidia CUDA Toolkit:

apt-get install ocl-icd-libopencl1 nvidia-cuda-toolkit