booting linux - xinitrc workings

See also 2 Downloads
See also 4 Forums
See also 5 Contacts

The ~/.xinitrc file is a shell script read by xinit and 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 and startx programs starts the X Window System and works as first client programs on systems that cannot start X directly from /etc/init, or in environments that use multiple window systems. The ~/.xinitrc file is a simple way to start X, typically used in conjunction with the inittab method.

One of the main functions of ~/.xinitrc is to dictate which client for the X Window System is invoked with the /usr/bin/startx and/or /usr/bin/xinit program 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.

Getting started

/etc/skel/ contains files and directories to provide sane defaults for newly created user accounts. (The name skel is derived from the word skeleton, because the files it contains form the basic structure for users' home directories.) The xorg-xinit package will populate /etc/skel with a framework .xinitrc file.

                  : ~/.xinitrc is a so-called 'dot' (.) file. Files in a *nix file 
                  system which are preceded with a dot (.) are 'hidden' and will not show up with a regular ls command, usually 
                  for the sake of keeping directories tidy. Dot files may be seen by running ls -a. The 'rc' denotes Run Commands
                  and simply indicates that it is a configuration file. Since it controls how a program runs, it is (although 
                  historically incorrect) also said to stand for "Run Control".

Copy the sample /etc/skel/.xinitrc file to your home directory:

              $ cp /etc/skel/.xinitrc ~/

Now, edit ~/.xinitrc and uncomment the line that corresponds to your DE/WM. For example, if you want to test your basic X configuration (mouse, keyboard, graphics resolution), you can simply use xterm:

                # ~/.xinitrc
                # Executed by startx (run your window manager from here)

                # exec gnome-session
                # exec startkde
                # exec startxfce4
                # exec wmaker
                # exec icewm
                # exec blackbox
                # exec fluxbox
                # exec openbox-session
                # ...or the Window Manager of your choice
                exec xterm

: It is important that only one exec line is uncommented, or else only the first uncommented line will be run.

After editing ~/.xinitrc properly, it's time to run X. To run X as a non-root user, issue:

                $ startx                


                $ xinit                

Your DE/WM of choice should now start up. You are now free to test your keyboard with its layout, moving your mouse around and of course enjoy the view. If you experience trouble with automounting, try inserting ck-launch-session between the exec statement and the DE/WM statement. For example:

                $ exec ck-launch-session gnome-session               

: This requires that you have the consolekit package installed.

The ck-launch-session part ensures that the various environment variables are set correctly by starting a clean ConsoleKit session. ConsoleKit is a framework for keeping track of the various users, sessions, and seats present on a system. It provides a mechanism for software to react to changes of any of these items or of any of the metadata associated with them. It works in conjunction with D-Bus and other tools.

Related Links

See also 1 xinit workings


content has been adapted from xinit wiki