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 22.04 or 20.04 server, when using it as a remote desktop.

[powerkit_alert type=”info” dismissible=”false” multiline=”true”]Important Note

Currently I’m using this with remote desktops that I’m connecting to via xRDP. This may not work for all remote desktop solutions, or all scenarios, however.

I’ve added in how to switch desktop environments for Chrome Remote Desktops, and another section for VNC, after realizing the method is different.

If your scenario is different and this method doesn’t work for you then please feel free to contact us via the comments section or our contact us page.[/powerkit_alert]

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 in this tutorial. The server I use is from Contabo; they offer powerful servers at very low prices. You can read my review here.

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 for xRDP

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.

[powerkit_alert type=”warning” dismissible=”false” multiline=”true”]However you’ll be prompted to fill in your password again, so each time you’ll have to login twice. I haven’t managed to fix this myself on Ubuntu 20.04.

I had found this solution here Froth and Java – Ubuntu Budgie and xRDP, but it hasn’t worked for me.

I’ll update this article when I find a fix.[/powerkit_alert]

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 22.04 / 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.
[Mah 6th 2022]: Tested switching desktops and Budgie workaround on Ubuntu 22.04.

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
You May Also Like
How to Create Sudo User in Debian 10
Read More

How to Create a Sudo User in Debian

[powerkit_collapsible title=”Not using Debian? Choose a different version or distro.”] Ubuntu CentOS [/powerkit_collapsible] The sudo command (originally standing…