Warning: THE VOID WIKI IS DEPRECATED. It is no longer being maintained, contains outdated and incorrect information, and will eventually be shut down. Please refer to the Void Handbook, https://docs.voidlinux.org/, for the official documentation. If you can't find the information you're seeking, please raise an issue at https://github.com/void-linux/void-docs/issues

Xinitrc -

From Void Linux Wiki
Revision as of 22:03, 8 August 2017 by GreattoBeGrateful (talk | contribs) (Fixed internal link to 'desktop environments')
Jump to navigation Jump to search

Related articles

The ~/.xinitrc file is a shell script read by xinit and by its front-end startx. It is mainly used to execute desktop environments, window managers and other programs when starting the X server (e.g., starting daemons and setting environment variables). The xinit program starts the X Window System server and works as first client program on systems that are not using a display manager.

One of the main functions of ~/.xinitrc is to dictate which client for the X Window System is invoked with startx or xinit programs on a per-user basis. There exists numerous additional specifications and commands that may also be added to ~/.xinitrc as you further customize your system.

Most DMs also source the similar xprofile before xinit.

This article was taken partly or wholly, with or without modification from: ArchWiki


Install the xinit package, which provides both xinit and startx, and a default xinitrc configuration file.


If .xinitrc is present in a user's home directory, startx and xinit execute it. Otherwise startx will run the default /etc/X11/xinit/xinitrc.

Note: Xinit has its own default behaviour instead of executing the file. See man 1 xinit for details.

This default xinitrc will start a basic environment with Twm, xorg-xclock and Xterm (assuming that the necessary packages are installed). Therefore, to start a different window manager or desktop environment, first create a copy of the default xinitrc in home directory:

$ cp /etc/X11/xinit/xinitrc ~/.xinitrc

The reason of doing this (instead of creating one from scratch) is to preserve some desired default behaviour in the original file, such as sourcing shell scripts from /etc/X11/xinit/xinitrc.d. Scripts in this directory without .sh extension are not sourced.

Append desired commands and remove/comment the conflicting lines. Remember, lines following exec would be ignored. For example, to start openbox:


if [ -d /etc/X11/xinit/xinitrc.d ] ; then
    for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
        [ -x "$f" ] && . "$f"
    unset f

# twm &
# xclock -geometry 50x50-1+1 &
# xterm -geometry 80x50+494+51 &
# xterm -geometry 80x20+494-0 &
# exec xterm -geometry 80x66+0+0 -name login

## some applications that should be run in the background
xscreensaver &
xsetroot -cursor_name left_ptr &

exec openbox-session
Note: At the very least, ensure that the if block in the example above is present in your .xinitrc file to ensure that the scripts in /etc/X11/xinit/xinitrc.d are sourced.

Long-running programs started before the window manager, such as a screensaver and wallpaper application, must either fork themselves or be run in the background by appending an & sign. Otherwise, the script would halt and wait for each program to exit before executing the window manager or desktop environment. Note that some programs should instead not be forked, to avoid race bugs, as is the case of xrdb. Prepending exec will replace the script process with the window manager process, so that X does not exit even if this process forks to the background.


To now run Xorg as a regular user, issue:

$ startx


$ xinit -- :1 -nolisten tcp vt$XDG_VTNR

Your window manager (or desktop environment) of choice should now start correctly.

To quit X, run your window manager's exit function (assuming it has one). If it lacks such functionality, run:

$ pkill -15 Xorg
Note: pkill will kill all running X instances. To specifically kill the window manager on the current VT, use:
WM_PID=$(xprop -id $(xprop -root _NET_SUPPORTING_WM_CHECK \
| awk -F'#' '{ print $2 }') _NET_WM_PID \
| awk -F' = ' '{ print $2 }')

kill -15 $WM_PID

The program xprop is provided by the package xorg-xprop in the official repositories.

Autostart X at login

Note: These solutions run X on the same tty used to login, which is required in order to maintain the login session.

For Bash, add the following to the bottom of ~/.bash_profile. If the file does not exist, copy a skeleton version from /etc/skel/.bash_profile. For Zsh, add it to ~/.zlogin (or ~/.zprofile) instead.

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx
  • You can replace the -eq 1 comparison with one like -le 3 (for vt1 to vt3) if you want to use graphical logins on more than one VT.
  • X must always be run on the same tty where the login occurred, to preserve the logind session. This is handled by the default /etc/X11/xinit/xserverrc.
  • xinit may be faster than startx, but needs additional parameter such as -nolisten tcp.
  • If you would like to remain logged in when the X session ends, remove exec.

See also Fish#Start X at login.

Automatic login to the virtual console

This method can be combined with automatic login to virtual console.

Tips and tricks

Override xinitrc from command line

If you have a working ~/.xinitrc, but just want to try other WM/DE, you can run it by issuing startx followed by the path to the window manager:

$ startx /full/path/to/window-manager

If the window manager takes arguments, they need to be enquoted to be recognized as part of the first parameter of startx:

$ startx "/full/path/to/window-manager --key value"

Note that the full path is required. Optionally, you can also override /etc/X11/xinit/xserverrc file (which stores the default X server options) with custom options by appending them after --, e.g.:

$ startx /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR


$ xinit /usr/bin/enlightenment -- -nolisten tcp -br +bs -dpi 96 vt$XDG_VTNR

See also man startx.

{{Tip|This can be used even to start a regular GUI programs but without any of the window manager features. See also #Starting applications without a window manager. }

Making a DE/WM choice

If you are frequently switching between different DEs/WMs, it is recommended to either use a Display manager or add code to .xinitrc. The code described next consists of a simple few lines, which will take the argument and load the desired desktop environment or window manager.

The following example ~/.xinitrc shows how to start a particular DE/WM with an argument:


# Here Xfce is kept as default

case $session in
    awesome           ) exec awesome;;
    bspwm             ) exec bspwm;;
    catwm             ) exec catwm;;
    cinnamon          ) exec cinnamon-session;;
    dwm               ) exec dwm;;
    enlightenment     ) exec enlightenment_start;;
    ede               ) exec startede;;
    fluxbox           ) exec startfluxbox;;
    gnome             ) exec gnome-session;;
    gnome-classic     ) exec gnome-session --session=gnome-classic;;
    i3|i3wm           ) exec i3;;
    icewm             ) exec icewm-session;;
    jwm               ) exec jwm;;
    kde               ) exec startkde;;
    mate              ) exec mate-session;;
    monster|monsterwm ) exec monsterwm;;
    notion            ) exec notion;;
    openbox           ) exec openbox-session;;
    unity             ) exec unity;;
    xfce|xfce4        ) exec startxfce4;;
    xmonad            ) exec xmonad;;
    # No known session, try to run it as command
    *) exec $1;;

Then copy the /etc/X11/xinit/xserverrc file to your home directory:

$ cp /etc/X11/xinit/xserverrc ~/.xserverrc

After that, you can easily start a particular DE/WM by passing an argument, e.g.:

$ xinit
$ xinit gnome
$ xinit kde
$ xinit wmaker


$ startx
$ startx ~/.xinitrc gnome
$ startx ~/.xinitrc kde
$ startx ~/.xinitrc wmaker

Starting applications without a window manager

It is possible to start only specific applications without a window manager, although most likely this is only useful with a single application shown in full-screen mode. For example:


exec chromium

With this method you need to set each application window's geometry through its own configuration files, if possible at all.

Tip: This method can be useful to launch graphical games, especially on systems where excluding the memory or CPU usage of a window manager or desktop environment, and possible accessory applications, can help improve the game's execution performance.

See also Display manager#Starting applications without a window manager.