It is normal for nvidia drivers to break Your system, or even not install at all. Have hammer by Your side, in case You would need to kill Your machine quickly.
As per How to disable Nouveau kernel driver
echo "blacklist nouveau" > /etc/modprobe.d/blacklist-nouveau.conf
echo "options nouveau modeset=0" >> /etc/modprobe.d/blacklist-nouveau.conf
update-initramfs -u
reboot
# Check PCI devices
lspci
# Check drivers for Your GPU
sudo ubuntu-drivers devices
# Install newest driver for Your GPU
sudo apt install nvidia-driver-470-server
# Reboot to load new kernel
reboot
# Check if driver works
nvidia-smi
# Install CUDA Toolkit
sudo apt install nvidia-cuda-toolkit
# Check if nvcc works
nvcc
Check out CUDA Tutorial and CUDA by Example.