might be more simple to pull the source from nvidia, i did that a few months back for a crypto mining rig.
The general procedure
sudo apt-get install dkms build-essential linux-headers-generic
sudo apt-get purge --remove nvidia*
wget nvidia and cuda
chmod +x both
ctrl+alt+f1 to init1
su to root
sudo service lightdm stop / sudo service gdm stop )
(cant recall if neveau blacklist required, the installer will let you know. If - may see How to disable Nouveau kernel driver)
ctrl+alt+f3 to init3 if the installer wants network access
if the installer fails for some reason and you need to reboot, end up with black screen - hit ctrl+alt+f1 for init1 again and resume setup or uninstall the failed install with ./installer.run --uninstall.
./installer.run
nvidia-smi or `cat /proc/driver/nvidia/version`
nvcc --version (or `-V` cant recall) altern `cat /usr/local/cuda/version.txt`