Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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
Question marked as Best reply

Posted on Jul 30, 2012 4:39 PM

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.

31 replies

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.

Aug 13, 2012 1:04 PM in response to Cimmy

I had this problem and solved it, although my circumstances may be a bit unique: A long time ago I tried an older version XQuartz in Snow Leopard. But I decided to stick with Apple's X11, so I disabled XQuartz by issuing the launchctl unload command as described in the XQuartz FAQ.


This past weekend, I upgraded from Snow Leopard to Mountain Lion. When I tried to start Gimp, I got a screen informing me that I needed to install XQuartz. I installed version 2.7.2, logged out, and logged back in. Gimp wouldn't start, and when I started Terminal, my DISPLAY variable was not defined.


I thought that a reinstall of XQuartz would re-enable launchd, but apparently that did not happen. So I issued the following terminal command:

launchctl load -w /Library/LaunchAgents/org.macosforge.xquartz.startx.plist

logged out, and back in, and that fixed my problem! You might want to try this command; it may not help you but it can't hurt.

May 9, 2013 3:55 AM in response to Cimmy

Thanks for this. Let me pass along my experience. X11 has been working fine for me for years, but all of a suddent $DISPLAY was no longer getting set.


I was pulling my hair out until I found this thread. I looked and sure enough launchctl was not showing that X11 was running on startup at all. I looked in /Library/LaunchAgents and it was entirely empty.


And why was it empty? About a week ago, I was having problems with my MBP which eventually led to a logic board replacement. Appled had tried to diagnose it over the phone, and *** part of their usual procedure was to have me entirely delete /Library/LaunchAgents/ and ~/Library/LaunchAgents ***. Not knowing any better I went ahead and did what they told me to. So, naturally, X11 was not starting up properly.


Well, problem solved... I re-installed XQuartz and now $DISPLAY is getting set properly.

May 14, 2013 7:48 AM in response to Dave Lasker

/Library/LaunchAgents


contains launchd items installed by third-party applications, so under normal circumstances, the advice from Apple to clean that directory out is good advice. X11 is now technically third-party, so that is why /Library/LaunchAgents/org.macosforge.xquartz.startx.plist resides where it does. If the file is present, but X11 is still not launching automatically, due to having been deactivated somehow, the command


launchctl load -w /Library/LaunchAgents/org.macosforge.xquartz.startx.plist


should restore the expected behavior.

Dec 11, 2013 11:21 AM in response to Frank Caggiano

I had the same exact problem as Cimmy and was going completely crazy looking for an answer... but I did what Frank Caggiano suggested and it worked perfectly!


local $ grep DISPLAY ~/.*rc ~/.login ~/.*profile ~/.MacOSX/environment.plist 2>/dev/null

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



Now I get:


$ echo $DISPLAY

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


Instead of 2 blank lines, and I can launch xterm and xgterm 🙂


Thank you so much!!!

Jan 11, 2014 10:45 AM in response to Cimmy

I recently had this problem with Mavericks, but resolved it as follows:


(1) From XQuartz, open an X terminal (xterm).


(2) Within your X terminal (xterm window), type


echo $DISPLAY


On my computer, this command gives the output :3. So now you know what your DISPLAY environment variable should be set to.


(3) Within a standard (not X) terminal, type


export DISPLAY=:3


Now xdvi (and other X applications) should (might, hopefully will) work within a standard terminal. Of course, you could add the export command to your .profile file, so that your DISPLAY variable is automatically set whenever you open a new terminal.

Jan 15, 2014 4:29 PM in response to ardenton

Update:


Sorry, forget my previous suggestion. Simply rebooting (MacBook Pro, running Mavericks) after installing XQuartz seems to be a more effective solution. After rebooting, my DISPLAY variable was reset as follows:


echo $DISPLAY


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


and I now can run X applications (xdvi, xclock, etc.).

Feb 21, 2016 6:10 PM in response to Cimmy

Hi All,

I have been using Snowleopard with X11 happily in the past but since I have upgraded to El Capitan and Quartz I face a very annoying issue. The problem is after I connect to my server using "ssh -X ..." it starts Quartz and everything works without any issue but when that specific terminal left idol for a short period of time, then I get the error of "cannot connect to display" error and I have to disconnect from server and reconnect with "ssh -X ..." again.


I would appreciate any suggestion on how to resolve this.


Many thanks in advance

Ashkan

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 ID.