How to Start X11 on Linux Without a Display Manager

While most modern Linux systems use a display manager to login users and start a desktop environment, it is possible to start X11 and your favorite window manager/desktop environment without one. You can start X from a virtual console and even set it to start automatically at login. Here’s how.


Step 1: Disable your display manager

Display managers were originally designed to connect remote users to a central server to run X applications. Users would use “X terminals”, not to be confused with xterm, which were graphical terminals designed for use with X11. Since most modern PCs run both the X server and applications on the same machine, you can disable them.

If you have a system running systemd, as is the case with most modern Linux distributions, you can disable your display manager at startup.

To do this, first find out which display manager you are using. A clue will be what desktop environment was installed by default. If you’re using GNOME, GDM is probably the display manager. If you are a KDE user, it is most likely KDM. Otherwise it could be XDM or LightDM.

If you’re not sure, a good place to start is to check the running processes with ps, top, or htop. Look for something in the listing that contains “-dm”.

If you know what display manager you’re running, you can easily disable it with systemd. Just use the systemctl Command. Here is an example for LightDM:

sudo systemctl disable lightdm.service

Reboot and you’ll be in a text-based virtual console. Enter your username and password when prompted, and you can run Linux commands in your shell as if you had a terminal window open. You use this to start your desktop, but first you need to set up yours .xinitrc File.

Step 2: Set up your .xinitrc

To start your window manager or desktop, you must first set up your .xinitrc file in your home directory. It’s easy. Just open it with your favorite text editor.

Now that you have it open you need to at least add the line that starts your preferred environment. Here is an example of starting XFCE:

exec startxfce4

It is important to use “exec” as it will cause you to be logged out of the system when exiting XFCE.

You can also have whatever programs you want to run when you start X in your .xinitrc. For example:

firefox &
xterm &
xcalc &
exec startxfce4

It is important to add the “&” at the end of any other program that runs before the desktop/window manager. This way they run in the background. If you don’t, the program will run and then nothing will happen unless you exit it. This doesn’t even start your window manager. The .xinitrc is really just a shell script and obeys the shell syntax.

Step 3: Using startx on the command line

Launching your favorite window manager or desktop environment is easy enough. Just type “startx” at the command line and once you’ve configured your .xinitrc file, it should run as if you logged in with a window manager.

If you want to start a different window manager than the one you set up in your .xinitrc, you can just use the manager’s absolute pathname as an argument:

startx /path/to/window/manager

Step 4: Start X automatically at login

You can also start X at login without a window manager. You can change the shell startup files that only run when you use a login shell. On bash this is .bash_loginand on zsh it is .zprofile.

Just add this sequence to the file:

If [ -z "${DISPLAY}"  ]  &&  [  "$XDG_VNTR" eq 1 ]; then
exec startx
fi

This part of the shell code checks that the $DISPLAY environment variable is empty (which it will be if X is not running) and that you are logged in to virtual console 1. That means another copy of X won if X is already running don’t spawn. It also won’t start if you start a shell in a terminal emulator, as that will run the .bashrc or .zshrc files instead.

You do not need a display manager when logging in

As with many things related to GUIs on Linux, running a display manager is strictly optional. You can start X on the command line and even when you log in automatically. You can run Linux completely without a GUI if you want.

Leave a Reply

Your email address will not be published. Required fields are marked *