240

How can I restart X Window Server from the command line?

I'd really like to be able to restart my GUI without having to do a full system reboot.

233

TL;DR: on systems with systemd (Ubuntu 15.04 and newer)

sudo systemctl restart display-manager

This will restart the appropriate display manager service (lightdm till 17.04, gdm3 after, sddm in Kubuntu, etc.). You can replace display-manager with lightdm, gdm3, sddm, etc. if needed, but this should be enough.

NOTE: This will forcefully quit all graphical programs, you'll lose any unsaved work, and you'll be logged out. Non-graphical programs will not be affected.


For other Ubuntu versions, first find which display manager your ubuntu is having with following command:

cat /etc/X11/default-display-manager

Than depending on what display manager, you can use one of the following commands:

  • Default Ubuntu (with LightDM)

    sudo restart lightdm  
    
  • Gnome (with GDM)

    sudo restart gdm
    
  • KDE (with KDM)

    sudo restart kdm
    

    Note: From 12.10 to 15.04, Kubuntu also uses LightDM.

  • For MDM (e.g. for Mint Cinnamon)

    sudo restart mdm
    
  • 4
    This probably changed for Unity. My system cannot find gdm. – Steven Roose Sep 16 '12 at 12:25
  • 1
    AFAIK Unity uses lightdm – txwikinger Mar 25 '14 at 23:51
  • 2
    It seem to close all the applications and documents immediately without saving (unlike regular restart), what's the difference between this and sudo reboot? – Amir Uval Feb 1 '15 at 16:23
  • 1
    @uval, sudo reboot reboots all your system, that is the computer, while this restarts only the Xorg server, so that other programs, which do not require a graphical interface, for instance a web server, can continue to work. As well as all mounter file systems (like encrypted ones), all connections to remote hosts etc. do persists in the case of this instead of the reboot command – user907860 Jun 16 '16 at 6:43
  • 1
    I get restart: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused. – William Oct 10 '16 at 18:16
38

For 11.04 and earlier:

sudo service gdm restart

For 11.10 and later:

sudo service lightdm restart

  • +1 Works nicely on the Raspberry Pi as well (in case anyone is curious, that's what got me here :) – Levon Aug 6 '14 at 18:03
14

Found out that you can do sudo pkill X

and it seems to work for me!

  • 1
    This rebooted my system, and not in a good way. Although I'm using Debian. – PJ Brunet Jun 22 '16 at 15:08
  • Works perfectly for me (I have no *dm service, Xorg is started directly upon user autologin). – zgoda Feb 24 '17 at 11:14
11

Newest version of Ubuntu as of 24 Oct, 2012.

  1. Open Dash Home
  2. Search for keyboard layout
  3. Click Options
  4. Expand tab labelled "Key sequence to kill the X server"
  5. Enable it and Close.

Command Line:

sudo restart lightdm
10

You can try pressing Ctrl+Alt+Backspace to restart X.

  • 7
    This is deactivated by default in 10.04 and will therefore normally not work. – Marcel Stimberg Aug 5 '10 at 18:28
  • 6
    It can be reactivated though, by going to System -> Preferences -> Keyboard, clicking the 'Options...' button in the 'Layouts' tab and enabling 'Key sequence to kill the x server'. – dv3500ea Aug 5 '10 at 18:33
  • 7
    The correct shortcut is "Alt+SysRq+k", however he asked for command line. – Li Lo Aug 5 '10 at 20:44
8

Since ubuntu 9.04 Ctrl+Alt+Backspace is disabled, however you can now type Alt gr + Print Screen + K.

http://www.sudo-juice.com/ubuntu-11-10-restart-x-shortcut/

  • Alt+PrtScr/SysReq+k logged me out pdq and my programs were killed or terminated. Is this the desired behaviour expected when restarting X-server? I have 11.10 and sudo restart lightdm took me into text mode and seemed to stay there shutting down a bunch of daemons then stopping. I had to reboot manually fortunately the off button does it gracefully (sometimes). – Asher Dec 22 '11 at 15:49
  • 5
    SysRq+k kills all running processes and child-processes on the current terminal (i.e. the one running your X-server). Using it may cause the system to lose data! See: askubuntu.com/questions/14155/… – Stefano Palazzo Dec 22 '11 at 17:50

protected by Community Mar 4 '13 at 3:43

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.