How to disable GUI in Ubuntu

13,060

Solution 1

You can use systemctl to "isolate" targets, which is to some extend similar to switching runlevels. The targets of interest here are

  • graphical.target

  • multi-user.target

Confusingly, graphical.target is the default target in both Ubuntu desktop and server, but since there is no display manager installed in server it's essentially the same as multi-user.target.

Switch while Ubuntu is running

Switch to "text mode" (you can simply run this in e.g. gnome-terminal):

sudo systemctl isolate multi-user.target

Switch to "graphical mode":

sudo systemctl isolate graphical.target

Set boot target

You can set the default target that is reached after boot (persists across reboot), e.g.:

sudo systemctl set-default multi-user.target

You can also set a target with the kernel parameter systemd.unit, e.g.

systemd.unit=multi-user.target

The kernel parameter has precedence over the default target.

This can be used to boot to a specific target once by editing the grub boot entry before boot. Or you could add multiple boot entries for different targets.

Solution 2

You can use systemctl(the systemd system and service manager) to control your display manager. In the case of Ubuntu, this is GDM - Gnome Display Manager, SDDM and LightDM are other common display managers.

To check the status from the command line:

sudo systemctl status gdm

To stop:

sudo systemctl stop gdm

To start:

sudo systemctl start gdm

To disable (prevent loading at system startup):

sudo systemctl disable gdm

To enable (loading at system startup):

sudo systemctl enable gdm

Solution 3

Another way of achieving this is to edit the line beginning with the linux command on your grub entry and add the number 3 at the end to boot in runlevel 3 which won't start x-server at all by default.

It should look something like this :

 linux  /boot/vmlinuz-5.3.0-46-generic root=UUID=SOME_UUID ro quiet splash 3

This has the same result as others have pointed out , but you can change it even before the system boots up.

In the grub menu press the e button on the ubuntu menu entry and after putting 3 at the end of the line , just press Ctrl+x to boot. Note that this won't save this config for you. If you want to save it , you must edit the file /boot/grub/grub.cfg. (And this is the scenario if you cannot get the grub menu at boot screen , because for example grub's timeout was set to zero. )

And another option for you is to install Ubuntu server which doesn't have GUI at all. unless you have a reason to stick with the desktop version. (e.g desktop version has more tools installed by default , like g++ ).

Share:
13,060
customcup
Author by

customcup

Updated on September 18, 2022

Comments

  • customcup
    customcup over 1 year

    Say if I wanted to replicate Ubuntu Server and have no GUI running what would I do to make this happen? Upon running htop/top from tty session I see both gnome and xorg are still running and sucking up quite a substantial amount of memory (I'm using VirtualBox and have 1024MB allocated to Ubuntu). I would preferably want the ability to disable/stop gnome and Xorg whenever I wish in order to free resources. I don't see any point in switching to tty from Xorg and keeping the processes running. I would however like to have the ability to re-enable/start the necessary files upon leaving tty. I do not want things to be permanently disabled although having this option would be useful/

    Any help? Thanks

  • Carsten S
    Carsten S almost 4 years
    Could you add the information whether this change persists across reboots?
  • steeldriver
    steeldriver almost 4 years
    @CarstenS isolate is ephemeral; to make it persistent use set-default
  • Martin Zeitler
    Martin Zeitler almost 4 years
    One probably should add, that this is about the same as running init 3... while init 5 would still bring up the GUI, because it never had been disabled, as it had been requested.
  • customcup
    customcup almost 4 years
    This answer seems to work. However when I type in the command for switching to text mode I have to manually switch to a tty session using CTRL+ALT+F*. If I don't I'm just left with a blinking cursor and no text. Is there a way to do this while referring to exactly what session I want?
  • danzel
    danzel almost 4 years
    @customcup which Ubuntu version do you use? In my 18.04 virtualbox VM, I get a login screen on tty1 after isolating multi-user.target. Did you run it in a tty or in a terminal emulator inside gnome?
  • Parsa Mousavi
    Parsa Mousavi almost 4 years
    @MartinZeitler Yes you're right. Each of the answers here are just one of the possible solutions.Sometimes there are lots of different ways to do the same task.
  • Martin Zeitler
    Martin Zeitler almost 4 years
    It does not disable the GUI, therefore it does not answer the question.
  • Peter Cordes
    Peter Cordes almost 4 years
    typo: quite should be quiet.
  • customcup
    customcup almost 4 years
    @danzel 20.04 and I'm doing it through terminal emulator
  • Norrius
    Norrius almost 4 years
    The question asks about shutting down X temporarily (and re-enabling later), so that doesn't really help.
  • customcup
    customcup almost 4 years
    @danzel pretty sure I replied. I'm doing it through terminal emulator but I'm just getting blinking cursor and no tty
  • Parsa Mousavi
    Parsa Mousavi almost 4 years
    @PeterCordes Edited.Thanks.
  • Parsa Mousavi
    Parsa Mousavi almost 4 years
    @MartinZeitler I think the intention was to somehow kill Xorg and Gnome and prevent them to be restarted to make more room for other programs. It doesn't necessarily mean to remove the GUI completely as stated by the OP : "I do not want things to be permanently disabled although having this option would be useful" . If we run the OS in the runlevel 3 then we have GUI disabled , although it can be re-enabled , but for now is disabled. So I don't think anything is wrong with it.