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

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.

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

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.