how to shut down X server on Ubuntu?

Getting this:
ERROR: You appear to be running an X server; please exit X before
installing. For further details, please see the section INSTALLING
THE NVIDIA DRIVER in the README available on the Linux driver
download page at

Was able to do it before had to flash computer and now unable to shut it down.
Please help.

Normally stopping the Display manager is enough to stop X

sudo systemctl stop lightdm.service

The more general way would be systemctl stop display-manager I think.

I tried the stop lightdm service through 3 different syntaxes I found online. The first time I did it it worked that way but I had a crash and had to redo everything, the second time that just kept making my screen black, this is where I got stuck. I tried the other two commands similar as well one was with kdm. Luckily I did find a way around it by doing the install in a different manor but still I would keep this thread going for answers because I was not the only person online who hadn’t found the right answer for their similar situation yet. The good news is if you do the install fully manually you don’t have to shut down the X. “sudo apt-get install nvidia-375 (something like that)” works without it, but when you try to run the .run file you download from Nvidia driver site you have to shutdown X, which appears to make problems.