0

What is the purpose of the $DISPLAY variable in X-Windows? How does it work?

I'm running fedora off a VM and don't know if I'm running X-Windows correctly to even answer the question. I go to the terminal and enter sudo startx and then I just get a blank screen and can't escape it. I know (I think) it's just a way to run a minimal sort of OS where you run everything from the command line.

  • sudo startx is usually a death warrant for X's permissions. Never run startx as sudo. – Akito Mar 31 '17 at 18:05
  • If it's only a VM image, can't you just reinstall the OS? – Akito Mar 31 '17 at 18:11
  • Which desktop environment do you use? – Akito Mar 31 '17 at 18:12
  • Yeah, I only did sudo once and just restarted it's not a big deal. And been using GNOME fedora environment is the one I'm using I also installed lxde and xfce. – fafa Mar 31 '17 at 18:58
2

The DISPLAY environment variable indicates to applications where to send GUI commands such as “create a window”, “display some text”, “draw an image”, “wait for a key or mouse click”, etc. It's the counterpart for graphical user interfaces of the standard streams for text mode applications.

For the most part, you don't need to care about this variable. If you run a program from a GUI session, the variable is already set. If you run a program over SSH, the variable is set automatically if you're forwarding the GUI, and if it's not set, that indicates that you aren't forwarding the GUI and setting the variable won't help. You only need to set the variable when you want to interact with a GUI session from the outside, for example to run a GUI program in a cron job, or to display a program on a machine's screen with the program started from an SSH session to that machine.

To start a GUI session, there are two methods: either log in first then start the GUI, or start the GUI and log in from there.

  • If you've logged in on a text mode console, you can start the GUI environment with the command startx. This command starts an X11 server (the GUI backend, that does basic things like remember that a certain window is at a certain position) as well as a bunch of useful applications, typically at least a window manager (a program that provides ways to switch between windows, to move windows around and control which one is active, to start programs, etc.) and often a desktop environment (that completes the window manager with additional screen widgets and utilities such as a clock, a desktop switcher, an icon tray, a session saver, etc.).
  • Most distributions for desktop use set up a display manager. The X server runs and the only program on screen is the display manager, which is a program that displays a login prompt. Once you log in, a session is started, just like the second part of startx (with a window manager, etc.).

If you haven't installed a display manager, you can choose between gdm, kdm, lxdm, slim, etc. Use e.g. sudo yum install gdm to install one.

If you don't want to install a window manager, or you want to start a GUI session from a console login for any reason, run just startx, not sudo startx. Many GUI programs are not meant to run as root and some environments will simply refuse to start if they're running as root.

-1

When you enter console mode again, login with username and password, then issue the command sudo /etc/init.d/gdm stop To stop the desktop environment's service. sudo dpkg-reconfigure xserver-org To reconfigure your xserver. Start your DE again: sudo /etc/init.d/gdm start

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.