X Display Server  «Prev  Next»
Lesson 7Configuring an X startup with .xinitrc
Objectiveconfigure X startup with .xinitrc

Configuring an X startup with .xinitrc

Here's how to configure X startup with `.xinitrc` in Red Hat Linux:
  1. Locate the `.xinitrc` file: The `.xinitrc` file is typically located in your home directory (`/home/<username>/.xinitrc`). However, if it doesn't exist, you'll need to create one. You can use a text editor like `nano` or `vim` to create and edit the file.
  2. Define your desired desktop environment: In the `.xinitrc` file, specify the command to launch your desired desktop environment. Here are some common examples:
    • GNOME:
      exec /usr/bin/gnome-session
      
    • KDE Plasma:
      exec startkde
      
    • LXDE:
      exec /usr/bin/startlxde
      
    • XFCE:
      exec startxfce4
      
  3. Add additional configurations (Optional): You can use the `.xinitrc` file to configure additional aspects of your X session startup. Here are some examples:
    Setting environment variables:
    # Set environment variable for DISPLAY
    export DISPLAY=:0.0
    
    # Set path to a custom font
    export FONT=“/path/to/your/font.ttf”
    

    Launching additional applications:
    # Start a terminal emulator in the background
    exec /usr/bin/xterm &
    
    # Launch a file manager
    exec /usr/bin/thunar &
    
  4. Make the file executable: Once you have added your desired configurations, make the `.xinitrc` file executable using the following command:
    chmod +x ~/.xinitrc
    
  5. Starting the X session (Optional): If you're not using a display manager that automatically starts the X session, you can use the `startx` command to launch X with your `.xinitrc` configuration:
    startx
    

Important Notes:
  • The specific commands and paths might differ slightly depending on your Red Hat Linux version and installed desktop environments. Refer to your distribution's documentation for exact details.
  • Ensure you have the necessary desktop environment packages installed before attempting to launch them in your `.xinitrc` file.
  • Remember to replace placeholders like `<username>` with your actual username.

By following these steps, you can configure your X startup with `.xinitrc` in Red Hat Linux to launch your preferred desktop environment and customize your X session with additional settings.

Yes, `.xinitrc` is still used to configure the startup of the X Window System (often simply called "X") on systems that use it, including Red Hat Linux. The `.xinitrc` file is a shell script read by `xinit` and `startx` to configure the environment for X sessions. This script allows users to customize their session by setting environment variables, starting a window manager, and running various startup programs.
However, it's important to note that many modern Linux distributions, including recent versions of Red Hat, have moved to using display managers (like GDM, LightDM, or SDDM) and desktop environments that rely on `systemd` for initializing user sessions rather than directly using `xinitrc`. For setups that still use the traditional start-up process without a display manager, `.xinitrc` remains relevant and useful for configuring the X environment.


Question: How do you configure X startup with .xinitrc?
The default X configuration is not customized at all. To make good use of the GUI, you may want certain programs to start as soon as you log in. You might want to open an xterm or two, an email window, a file browser, or a system resources monitor. The .xinitrc file can be used to control this startup behavior.

Starting Applications

When the X server starts, it loads the applications you specify from .xinitrc, which resides in your home directory. You may start any application you want by listing its full path followed by an ampersand (&) on each line of .xinitrc. For example, to start the xclock application, you simply need a line in your .xinitrc file such as /usr/X11R6/bin xclock &.
Of all the applications you start, the last one must be your "window manager", which allows you to make your environment user friendly. Any programs listed after the window manager will not run. The window manager must be the last line in .xinitrc.
Unlike the other programs listed in your .xinitrc file, do not include the ampersand after the window manager; if you do, your X session will not run. The following series of images below explores a simple .xinitrc file. Pay special attention to the seemingly peculiar string that follows the -g on lines 3 through 6.


1) The line executes the xrdb command with the load option.
1) The line executes the xrdb command with the load option. It loads the X resources database file located in the user's directory.

2) xsetroot sets the color of the root window (or background)
2) xsetroot sets the color of the root window (or background) to solid gray.

3) These commands bring up a clock and a CPU load indicator.
3) These commands bring up a clock and a CPU load indicator. The -g option signifies that a geometry specification follows.

4) The first pair of numbers, separated by an x give the size of the window in pixels in the form width X height.
4) The first pair of numbers, separated by an x give the size of the window in pixels in the form width X height. The second pair of numbers indicates window positioning, the first of these is the horizontal position, and the second is the vertical position. A number preceded by a (+) indicates position relative to the top or left hand side of the screen, whereas a (-) indicates that the following number is relative to the bottom of right hand side of the screen

5) here are two lines of code that indicate initial xterms will start.
5) There are two lines of code that indicate initial xterms will start. The last line starts the window manager. The exec command tells xinit to start the window manager and have the X clients be child processes of it. If just the window manager executable is supplied, it will be a child of a shell spawned by X. The X clients would then also be child processes of this shell.

How do you configure an X startup with .xinitrc?

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 (i.e., 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.
More information about .xinitrc can be found in the xinit man page. The next lesson concludes this module.


SEMrush Software 7 SEMrush Banner 7