sudo ubuntu-drivers devices
Visit the Official Nvidia website.
sudo wget https://us.download.nvidia.com/XFree86/Linux-x86_64/510.60.02/NVIDIA-Linux-x86_64-510.60.02.run
sudo apt install build-essential libglvnd-dev pkg-config
Before installing the driver, it is mandatory to stop your current display server by changing the run level to 3.
sudo telinit 3
sudo bash NVIDIA-Linux-x86_64-510.60.02.run
Restart run level 6.
sudo init 6
NOTE: This will reboot your system and start it with display server on.