How to exit the X server to install the NVIDIA driver?

When I open the folder, where the driver is, in the terminal and type “./NVIDIA-Driver.run” (this is the name I gave to the file) this appears:

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 www.nvidia.com.

In section 4 - Installing the NVIDIA Driver on the Readme page it says to exit the X server, but it doesn’t say how to do that.

I typed these two commands in the terminal, the first one the screen went black and my PC restarted and when it came back I tried it and the same error appeared. The second, nothing happened and after the retry, the same error.

systemctl stop display-manager
systemctl stop lightdm.service

Now it’s up to you, friends, it’s you I’m counting on.

You shouldn’t use the runfile installer at all, please use the driver from the repo of your distribution.
sudo systemctl isolate multi-user.target
should turn off graphics.

I gave up installing by the runfile installer. I preferred to install with this command:

sudo apt-get install nvidia-driver-515

How do I exit TTY and turn graphics back on after typing this command without restarting the machine?

I did that but had to type the reboot command to get back.