Nvidia Drivers in Ubuntu

Check the driver which is being used for Nvidia card with the following command.

sudo lshw -c display

You can also use video instead of display.

sudo lshw -c video

By default, the open source nouveau driver is being used for Nvidia card.

Run the following command to list available driver for your Nvidia card from the default Ubuntu repository.

sudo ubuntu-drivers devices

install the recommended driver, run the following command.

sudo ubuntu-drivers autoinstall

If you want to install a particular driver, run the following command.

sudo apt install nvidia-driver-version-number

For example:

sudo apt install nvidia-driver-340

After the driver is installed, Reboot the computer to enable nvidia-prime, which is technology to switch between Intel and Nvidia graphics card.

sudo shutdown -r now

Now the proprietary Nvidia driver is being used.

sudo lshw -c display

Removing Nvidia Drivers

Search what packages from nvidia you have installed.

dpkg -l | grep -i nvidia

Nvidia-common package has a dependency on ubunut-desktop.

To purge everything related to nvidia you can give this command

sudo apt-get remove --purge nvidia-*

Above command will also remove the nvidia-common package and the nvidia-common package has as a dependency the ubuntu-desktop package.

So after above command you should also give the installation command for ubuntu-desktop package

sudo apt-get install ubuntu-desktop

Also sometimes the nouveau driver get blacklisted from nvidia driver. With purge command it should UN-blacklisted. If you want to be sure that nouveau will be load in boot, you can force-load it by add it to /etc/modules

echo 'nouveau' | sudo tee -a /etc/modules

Last , search for the xorg.conf file and remove it as well

sudo rm /etc/X11/xorg.conf

In summary

sudo apt-get remove --purge nvidia-*
sudo apt-get install ubuntu-desktop
sudo rm /etc/X11/xorg.conf
echo 'nouveau' | sudo tee -a /etc/modules

LightDm install directory missing

t is possible that the folder /var/lib/lightdm has not been created.

You could try: mkdir -p /var/lib/lightdm; chown -R lightdm:lightdm /var/lib/lightdm ; chmod 0750 /var/lib/lightdm with root permission if needed.

Reference:
https://www.linuxbabe.com/ubuntu/install-nvidia-driver-ubuntu-18-04
https://askubuntu.com/questions/692577/ubuntu-15-10-boot-hangs-when-starting-lightdm
https://askubuntu.com/questions/206283/how-can-i-uninstall-a-nvidia-driver-completely