Stop Screen Tearing with Optimus Laptops using Nvidia Drivers in Linux (Including Ubuntu 18.04 and Solus)

Is screen tearing while using Nvidia drivers in Linux driving you nuts? Do you have an Optimus laptop? I believe we may have a solution for you!

I experienced this issue for quite some time before finally finding a fix. This would happen in Ubuntu Mate, Ubuntu and similar distributions where Prime was used as a method to switch between Nvidia and Intel drivers.

Typically on the Intel side of things, everything was fine but as soon as I switched to using my Nvidia driver, all hell would break loose. That was, until I found this solution buried in the Ubuntu forums.

In terminal –

sudo nano /etc/modprobe.d/zz-nvidia-modeset.conf
Now, you're going to add a line such as the one below, replacing 384 with whichever driver version you are using, Add this line, adjust 375 if using newer driver, ex. 381 or 384 ect.
options nvidia_375_drm modeset=1

Updated for Ubuntu 18.04: I took me a while to find this but if you are using Ubuntu 18.04 or any of it's derivatives and finding the above does not work, it's because prime synchronization does not require the driver number. The proper command should be:

options nvidia_drm modeset=1

Save and exit nano

Now type:
sudo update-initramfs -u

Reboot and keep your fingers crossed. If all goes well, things should be fixed.

Update for Solus users:

Go to /usr/lib/modprobe.d and make a file called zz-nvidia-modeset.conf. You then put the following code within it:
options nvidia_drm modeset=1
then run
clr-boot-manager update

Let me know if this works for you or if you have another workaround that has been successful.