XQuartz and DISPLAY variable

I would greatly appreciate help toward the resolution of an issue that I am having with Mountain Lion (ML) on my 2007 iMac. I like starting X11 applications from a terminal, and it used to be possible until I instaled ML. I understand I have to install XQuartz, log out and back in, but have done it all several times and I continue to be unable to do it. Specifically, the DISPLAY variable does not get set (output of echo $DISPLAY is just two blank lines).

On the other hand, ifI just start XQuartz and open an xterm I have no problem, i.e., the DISPLAY variable is set normally.

Interestingly, the same procedure works fine on my recently purchased (two weeks) MacBook Air. Any idea of how I might b able to fix this (I have already gone through the exercise of uninstalling XQuartz and redoing it, I have also rebooted the machine but the problem persists).

Thanks in advance.

iMac, OS X Mountain Lion

Posted on Jul 30, 2012 6:29 AM

Reply
31 replies

Jul 31, 2012 7:46 AM in response to Cimmy

So like he said, something must be clobbering the $DISPLAY variable. Or the launchd job isn't running. For what it's worth, I've just confirmed that the socket is supposed to be launched by a User Launch Agent named org.macosforge.xquart.startx, with the following contents:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>EnableTransactions</key>

<true/>

<key>Label</key>

<string>org.macosforge.xquartz.startx</string>

<key>ProgramArguments</key>

<array>

<string>/opt/X11/lib/X11/xinit/launchd_startx</string>

<string>/opt/X11/bin/startx</string>

<string>--</string>

<string>/opt/X11/bin/Xquartz</string>

</array>

<key>ServiceIPC</key>

<true/>

<key>Sockets</key>

<dict>

<key>org.macosforge.xquartz:0</key>

<dict>

<key>SecureSocketWithKey</key>

<string>DISPLAY</string>

</dict>

</dict>

</dict>

</plist>


So I think the troubleshooting steps should be:


Confirm you have the Launch Agent in the correct location (/Library/LaunchAgents/org.macosforge.xquartz.startx.plist);

Determine if launchd is running the job (ie, are permissions correct, etc, etc);

If so, is the job completing successfully (ie, is there a socket at some point);

If so, when is the socket getting clobbered?


Of course, if it's something in your shell profile clobbering $DISPLAY, then it may be a bit tricky to check the first two without opening a shell...but not impossible.

Jul 30, 2012 4:39 PM in response to Cimmy

Not sure what to suggest - I just checked on my installation and I do get a result for "echo $DISPLAY", referring to what looks like a unix socket at (currently) /tmp/launch-31NZS8/org.macosforge.xquartz:0.


I also tried launching Wireshark from the terminal. The first time I got a dialog asking where X11 was located, but after I pointed it at XQuartz everything worked without a problem.


Have you tried running "launchctl list | grep xquartz" to see if the XQuartz User Launch Agent is actually running? Perhaps that's the problem.

Jul 31, 2012 6:26 AM in response to Cimmy

DISPLAY only usually gets set by default when you're in an xterm or other X application.


That's the way the older X Window Server X11.app stuff worked on Lion and prior releases, too.


You won't find that opening Terminal.app will typically get DISPLAY set, for instance.


If you're seeing DISPLAY in a Terminal.app session on one system (but not on another), then check whatever shell scripts are being used to log into bash, and compare those with the system that isn't getting DISPLAY set. (That's usually the ~/.bash_profile, ~/.bash_login, and ~/.profile scripts, and only one usually gets executed. For grins, also check the /etc/profile script, but I'd tend to assume the changes weren't there.) See if, for instance, the XQuartz installation modified one of those scripts, and you're not using that script (but some other login script) in one of your two environments.

Jul 31, 2012 7:09 AM in response to MrHoffman

You won't find that opening Terminal.app will typically get DISPLAY set, for instance.

I think with Leopard, Mac OS X always provided a DISPLAY environment variable, and if something used DISPLAY's contents, X11 would be automatically be started.


Setting DISPLAY in a shell initialization file often messed up X11 on Mac OS X from Leopard onwards.


HOWEVER, I do not have any Mountain Lion experience (yet - I'm going to have to see about downloading a copy and maybe giving it a spin via VMware Fusion 🙂 -- I do have a flash drive on order so I can have a saved local copy of Mountain Lion installer).

Jul 31, 2012 7:25 AM in response to Cimmy

When you install Xquartz, log out, and log in again, it will, forever after, set the $DISPLAY variable automatically for you, as long as you don't try to set it manually somewhere in your shell initialization.


It should look something like the following:


zsh-% print $DISPLAY

/tmp/launch-vcKJJv/org.macosforge.xquartz:0


So my guess is that there is something clobbering the $DISPLAY.


Try changing your shell, and see if it works (if you have bash, for example, try switching to zsh with chsh -s /bin/zsh ). In the unlikely event you would want to switch back from zsh, you can just run the same command for /bin/bash

Aug 12, 2012 6:36 AM in response to Bill Scott

I am having the same problem and it looks like the problem is in userspace, because everything is correct under new user. Now I am just at loss here, how to correct things under current user, because the most obvious things like .bashrc, .bash_profile, .profile are all checked through and even thrashed once without any result.


It looks like moving my stuff under new user could be smarter move...

Aug 12, 2012 9:43 AM in response to nmt1900

What does your DISPLAY environment variable look like:


echo $DISPLAY


Does it look something like this:


/tmp/launch-egVRmr/org.x:0


The important thing being does it start with /tmp and end in colon 0 (I can't actually type : 0 as adjacent characters, as the forum thinks I'm putting in a smilie 😁 )


AND does the file exist in /tmp/mumble/somthing ?


If not, then you might also check if you created a $HOME/.MacOSX/environment.plist which is another way to customize the user's environment (EXCEPT on Mountain Lion where this has been discontinued).


Is ssh involved? In that .ssh/config can have setup information, which can affect logging into remote systems.


Are you having the problem connecting to a remote system and exporting your display back to the Mac? That could possibily be an issue with the remote system's shell initialization files.


Can you give us more information to work with?

Aug 12, 2012 10:27 AM in response to BobHarris

It looks like it should under new user ("/tmp/launch-egVRmr/org.x:0"-ish), but under my current user I get only an empty line as answer to echo $DISPLAY.


Switching the shell to zshell does not change anything - still the same empty line.


When I am logged in as new user, wireshark and other X11 applications will bring XQuartz up and everything works as it should.


On my current user there is no way to bring XQuartz up by other application and when this is tried from command line, then only answer is "cannot open display".


Removing and reinstalling XQuartz does nothing - which is obvious, because the problem does not seem to be on system level.


I have been trying to compare the files in LaunchAgents and other possible places between my current user and new one and have not find anything helpful.


I have not been logging into remote systems lately so I cannot say anything about that. Current user does not seem to have .ssh_config file and system-level ssh_config has XAuthLocation line added by XQuartz.


I do not have anything in $HOME/.MacOSX/ folder. No custom xinit files either.Have macports installed, but not X11 from there.


Wineskin Winery is installed and wineskin apps work without problem.

Aug 12, 2012 11:44 AM in response to Frank Caggiano

First one gives nothing, but second one does


$ grep -r DISPLAY /opt/local/etc /sw/etc /etc 2>/dev/null

/opt/local/etc/mc/mc.ext:# All X Apps [Nothing/Warning] if no DISPLAY

/opt/local/etc/mc/mc.ext: Open=if [ "$DISPLAY" = "" ]; then zgv %f; else (gqview %f &); fi

/opt/local/etc/mc/mc.ext: Open=if [ "$DISPLAY" = "" ]; then play %f; else (xmms %f >/dev/null 2>&1 &); fi

/opt/local/etc/mc/mc.ext: Open=if [ "$DISPLAY" = "" ]; then mpg123 %f; else (xmms %f >/dev/null 2>&1 &); fi

/opt/local/etc/mc/mc.ext: Open=if [ "$DISPLAY" = "" ]; then ogg123 %f; else (xmms %f >/dev/null 2>&1 &); fi

/opt/local/etc/mc/mc.ext: Open=if [ "$DISPLAY" = "" ]; then play %f; else (xmms %f >/dev/null 2>&1 &); fi

/opt/local/etc/mc/mc.ext: Open=if [ -z "$DISPLAY" ]; then mplayer -vo null -playlist %f; else (xmms -p %f >/dev/null 2>&1 &); fi

/opt/local/etc/mc/mc.ext: Open=(if test -n "" && test -n "$DISPLAY"; then ( file://%d/%p &) 1>&2; else links %f || lynx -force_html %f || ${PAGER:-more} %f; fi) 2>/dev/null

/opt/local/etc/mc/mc.ext: Open=if [ x$DISPLAY = x ]; then dvisvga %f; else (xdvi %f &); fi


Same input did not produce any output when logged in as new user, which is confusing.


Edit: Sorry - tried wrong line on new user. Both users are generating the same output, but one has problem, while another one has not.

Aug 13, 2012 3:37 AM in response to nmt1900

FWIW... I think I succeeded in "reconstruction" of this chain of post-upgrade events, that ended up in "unnecessary" command as solution.


I did upgrade to 10.8 the first day it came out, installed XQuartz 2.7.2 and noticed, that X11 apps did not want to work. Then I tried among other things to disable launchd action for XQuartz, which (obviously) did not help (among other stupid options). 😁


Then I tried other system-level things as reinstalling XQuartz and searching for possible solutions with google to no avail.


Then I found this thread and could pinpoint the problem to userspace (thanks to Bill Scott for the tip!) and started to search for possible plist files to thrash. Nothing seemed to help until I just tried this 'launchctl load' command and bingo!


Now I started to go through these thrashed plist files and found this pesky environment.plist file (from .MacOSX folder), which contained only one value, which defined $DISPLAY as ":0".


There you have it - initially things did not work because of this file, but I did not knew about this, then I did completely unnecessary 'launchctl unload', which of course did not help, but got forgotten.


Thrashing environment.plist also did not help because this previous unnecessary action. Finally when both problems were corrected, everything was fine. So first thing for upgraders from 10.6->10.7 might be checking environment.plist file.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

XQuartz and DISPLAY variable

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.