Install and start Xorg

(This is part of a larger series on finding your footing on Arch Linux.)

Last modified: 30 May 2022

Goal: Set up a minimal working graphical environment using the X Window System, the i3 window manager, and a terminal emulator of your choice; and help you understand and navigate the choices between window managers, desktop environments, and display managers.

Context: After installing of Arch and logging in, you’ll find yourself in a Linux console running a command-line shell, in which you can interact with your operating system using text-based commands. You’ll need a window system to do much more than that (e.g. run a web browser, use a standard terminal emulator, read PDFs, have windows appear on your screen, etc.). Most anything associated with modern desktop computing requires a window system.

References:

Contents

What’s involved

Making sense of all the Xs

Note: Feel free to skip to installation. The technical details in this section don’t matter much once you actually begin using a window system, and you usually won’t think about them or need them from the perspective of an everyday user.

Confusingly, the X window system, display server, and display server communication protocol are all called X in everyday usage. Wikipedia does a good job of explaining what’s involved; here’s my everyday-language summary:

Choices: Standalone window manager vs. desktop environment

To get a working window system, you’ll need to install both a display server and a window manager. A window manager controls the appearance, placement, stacking, tiling, etc. of windows, and will usually also provide multiple workspaces. The two common choices are:

  1. install a standalone window manager, or
  2. install a desktop environment, which will include a window manager.

A desktop environment (DE) is a bundle of well-integrated desktop-related software. A DE always includes a (potentially boring) window manager, and might also include toolbars, a dock, status bar, widgets, icons, an application launcher, a terminal emulator, a file browser, etc.

Common DEs include GNOME, KDE Plasma, and Xfce (there are many more); common standalone window managers include Bspwm, i3, and dwm (there are many more).

I lied above. You really have three choices, not two:

  1. Install a standalone window manager, then install any desired tool bars, widgets, etc. individually. You get a cool window manager and maximum customizability. This is what I’ll do in this tutorial.

  2. Install a DE and use its default window manager, which will do the job but might be boring. Desktop bells and whistles will be set up for you without requiring much work on your part.
    Typical DE use case: you don’t want to install and configure its components individually, and don’t mind potentially less customizability, a larger memory footprint, and (*shudder*) a bit more “bloat”.

  3. Install a DE and a window manager, and use this window manager instead of the default DE version. You get the convenience of a DE in addition to a cool window manager, but use a bit more disk space and computing resources.

Need help choosing a desktop environment or window manager? You can browse through a bunch of options on Ermanno Ferrari’s excellent desktop customization playlist.

Choices: Display manager or not?

It depends on how you want to log in. After a standard Arch install you log in by typing your username and password into a text-based console prompt displayed at the end of the boot process. After logging in, you enter a command line shell, and can then issue the startx command to start the X Window System.

A display manager (DM) is a graphical alternative to the login process—it’s basically graphical eye candy. A DM will display a graphical login window at the end of the boot process instead of a text-based console prompt. You’ll usually get a window with GUI text fields for your username and password, and will have the option to customize colors, background wallpaper, etc. You can also configure most DMs to start Xorg automatically after logging in.

My suggestion for beginners: begin without a display manager and log in using the text-based console—you’ll have fewer things to set up and potentially misconfigure. You can always install a DM after setting up your window manager and/or desktop environment.

Installing Xorg and i3

Here’s the minimal window setup I’ll cover on this page:

Installation

Install the following packages:

sudo pacman -S xorg xorg-xinit i3-wm i3status i3blocks

Explanation: xorg is a package group—it contains the Xorg display server and a collection of other useful X-related packages; xorg-init is used to start the X Window System; i3-wm is the i3 window manager; i3status and i3blocks provide the i3 status bar.

Starting X

You installed X; now you need to start it—we’ll use the startx program (provided by the xorg-xinit package) to start the X Window System and launch a window manager.

You configure startx’s behavior through the ~/.xinitrc file. We’ll use the default xinitrc file in /etc/X11/xinit/ as a starting point, and then change it slightly to start the window manager or desktop environment of your choice.

  1. First make a copy of the default xinitrc in your home directory:

    # Copy the default xinitrc from /etc/X11/xinit into your home directory
    cp /etc/X11/xinit/xinitrc ~/.xinitrc
    
  2. Open the just-copied ~/.xinitrc in a text editor, and you’ll see some boilerplate code interspersed with a mountain of empty lines. You can delete the empty lines if you like; supposedly they come from the pre-processor used to programmatically generate the xinitrc file—see this Arch forum discussion and this GitLab issue for a discussion of the empty lines.

    Scroll to the bottom of the ~/.xinitrc and you’ll see the following code:

    # At the bottom of the default xinitrc
    twm &
    xclock -geometry 50x50-1+1 &
    xterm -geometry 80x50+494+51 &
    xterm -geometry 80x20+494-0 &
    exec xterm -geometry 80x66+0+0 -name login
    

    This code starts the default Tab Window Manager (twm), a clock (xclock), and a few instances of xterm, which is the default X terminal emulator. The numbers just specify the screen coordinates where the clock and terminals should open.

    You’ll want to replace the Tab Window Manager code block with the executable of the desktop environment or window manager you have installed and plan on using. Example: to start the i3 window manager, delete the block beginning with twm & and replace it with the single line:

    # At the bottom of the default xinitrc
    exec i3
    

    (But make sure to keep all of the default xinitrc code from above the twm & block.)

    As a general rule, you should start long-running processes in the background by appending &, and start the last process in the xinitrc using exec, which replaces the shell process running the xinitrc script with the process you start with exec, which is usually your window manager, desktop environment, or a terminal emulator. See ArchWiki: Xinit/xinitrc and this StackExchange answer for more information about the xinitrc file.

  3. Install a terminal emulator. I suggest Alacritty if you want to follow along with this series or xterm (the default X terminal) if you want to decide later.

    sudo pacman -S alacritty  # to install Alacritty
    sudo pacman -S xterm      # to install xterm
    

    You should install a terminal emulator now to ensure you’ll have one available after you start your first X window session. You don’t want to start X and then realize you don’t have a graphical terminal emulator available.

  4. After creating an xinitrc file, you can start the X Window System by running startx from the Linux console. This will dump you into a new session of your window manager or desktop environment.

    If you’ve followed along with this tutorial and installed i3, you’ll probably be prompted to set your modifier key (Alt by default), and then you’ll see a blank screen with a spinning cursor. Don’t worry, nothing’s wrong—you just don’t have any windows open yet. You can start a terminal with the key combination Mod-Enter, where Mod is the key you chose as your i3 modifier.

Next steps