How to Switch Desktop Environments in Ubuntu/Debian From the Command Line

How to Switch Desktop Environment in Ubuntu_Debian From the Command Line

This comes in useful when needing to switch between desktop environments on a Ubuntu 20.04 server, when using it as a remote desktop.

Objective

In this tutorial we’ll switch between multiple desktop environments from the command line, on a machine running a Debian based Linux distro.

Prerequisites

  • A machine running a Debian based Linux distro with multiple desktop environments installed. (I’m using Ubuntu 20.04)

Switching Between Desktop Environments

To switch between desktop environments on a Debian based distro run the following command:

sudo update-alternatives --config x-session-manager

Then you should be presented with the desktop environments you have installed on your system so you can choose one of them:

There are 9 choices for the alternative x-session-manager (providing /usr/bin/x-session-manager).

  Selection    Path                      Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gnome-session     50        auto mode
  1            /usr/bin/gnome-session     50        manual mode
  2            /usr/bin/lxsession         49        manual mode
  3            /usr/bin/mate-session      50        manual mode
  4            /usr/bin/openbox-session   40        manual mode
  5            /usr/bin/startlxde         50        manual mode
  6            /usr/bin/startlxqt         50        manual mode
  7            /usr/bin/startplasma-x11   40        manual mode
  8            /usr/bin/startxfce4        50        manual mode
  9            /usr/bin/xfce4-session     40        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Then you can fill in the number corresponding to the desktop environment that you want and press enter.

Then you can logout and log back in, and the desktop launched should be the one that you selected.

Switching to Ubuntu Budgie Desktop Environment

The above method doesn’t seem to work with Ubuntu Budgie.

What does work, however, is editing the /etc/xrdp/startwm.sh file, by commenting out the last 2 lines, and adding budgie-desktop at the end.

To edit the file run:

sudo nano /etc/xrdp/startwm.sh

And comment out the last two lines and add budgie-desktop at the end:

# test -x /etc/X11/Xsession && exec /etc/X11/Xsession
#exec /bin/sh /etc/X11/Xsession
budgie-desktop

Restart xRDP:

sudo systemctl restart xrdp

Now when you log in again you should be using Ubuntu Budgie.

Switching Between Desktop Environments From the Command Line for Chrome Remote Desktop

To configure Chrome Remote Desktop to use a different desktop environment, then run the following command, replacing CHOSEN_DESKTOP_ENVIRONMENT with the desktop environment that you want.

sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/CHOSEN_DESKTOP_ENVIRONMENT" > /etc/chrome-remote-desktop-session'

For example, to configure Chrome Remote Desktop to use XFCE you would run:

sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/xfce4-session" > /etc/chrome-remote-desktop-session'

I’m not sure of a clean way of listing the paths for each desktop environment, at the moment, but you can run the following command and to see the path for each desktop environment:

sudo update-alternatives --config x-session-manager

As mentioned above, you’ll be shown something like the following, where you can see the executables for the desktop environments installed on your system under Path.

There are 9 choices for the alternative x-session-manager (providing /usr/bin/x-session-manager).

  Selection    Path                      Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gnome-session     50        auto mode
  1            /usr/bin/gnome-session     50        manual mode
  2            /usr/bin/lxsession         49        manual mode
  3            /usr/bin/mate-session      50        manual mode
  4            /usr/bin/openbox-session   40        manual mode
  5            /usr/bin/startlxde         50        manual mode
  6            /usr/bin/startlxqt         50        manual mode
  7            /usr/bin/startplasma-x11   40        manual mode
  8            /usr/bin/startxfce4        50        manual mode
  9            /usr/bin/xfce4-session     40        manual mode

Press <enter> to keep the current choice[*], or type selection number:

And you’ll use the Path for the desktop environment that you want, replacing /usr/bin/CHOSEN_DESKTOP_ENVIRONMENT with it.

sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/CHOSEN_DESKTOP_ENVIRONMENT" > /etc/chrome-remote-desktop-session'

Switching to Ubuntu Budgie Desktop Environment for Chrome Remote Desktop

The path to Budgie is /usr/bin/budgie-desktop so to switch to it you can run:

sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/budgie-desktop" > /etc/chrome-remote-desktop-session'

I’m not clear on how to find the path to Budgie in a clean command, however you can switch to it, right now. But the above command should work.

Switching Between Desktop Environments From the Command Line for VNC Server

To see how to switch between desktop environments from the command line for VNC, please visit our related article on installing and configuring a VNC server on Ubuntu 20.04, in the Configuring VNC to Use Other Desktop Environments (And Switching Between Them) section.

We cover this exact topic in detail in that section.

The reason we chose to add it as a section as part of that tutorial, instead of adding it here, is because it somewhat relies on the context of that specific tutorial.

We recommend reading through the entire tutorial in order to get some background info on how we set up our server.

For example, we mention that in that tutorial we’re using TigerVNC, and that TightVNC has not worked for every desktop environment for us.

Conclusion

I hope this article helps you in changing between desktop environments from the command line.

If you’re having any issues, or have any feedback, we’d love to hear from you in the comments or via the channels on our contact us page.

Resources & Acknowledgements

Alternative way of switching to Ubuntu Budgie Desktop Environment adapted from:


Revisions & Updates of this Article

[Mar 23 2021]: Added workaround to switch to Budgie, along with acknowledgements.

14 Shares:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
You May Also Like