Cimmy

Q: 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 4:11 PM

Close

Q: XQuartz and DISPLAY variable

  • All replies
  • Helpful answers

Previous Page 2 of 3 last Next
  • by Frank Caggiano,

    Frank Caggiano Frank Caggiano Aug 12, 2012 10:45 AM in response to nmt1900
    Level 7 (25,782 points)
    Aug 12, 2012 10:45 AM in response to nmt1900

    Try these two in the Terminal

     

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

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

     

     

    If either outputs anything that's were the DISPLAY varaiable is getting stepped on.

  • by nmt1900,

    nmt1900 nmt1900 Aug 12, 2012 11:44 AM in response to Frank Caggiano
    Level 1 (0 points)
    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.

  • by nmt1900,

    nmt1900 nmt1900 Aug 12, 2012 12:04 PM in response to Frank Caggiano
    Level 1 (0 points)
    Aug 12, 2012 12:04 PM in response to Frank Caggiano

    Now it looks like problem got solved. Very weird, but it was still launchd thing - I was trying to check it up among all other, but strangely I did something wrong before.

     

    All it was needed was

     

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

  • by nmt1900,

    nmt1900 nmt1900 Aug 13, 2012 3:37 AM in response to nmt1900
    Level 1 (0 points)
    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.

  • by Bill Scott,

    Bill Scott Bill Scott Aug 13, 2012 7:53 AM in response to Cimmy
    Level 6 (11,449 points)
    Aug 13, 2012 7:53 AM in response to Cimmy

    Look in ~/Library/LaunchAgents to see if there is something resetting $DISPLAY, and it might we worth doing a "ls -a" in your home directory, or gzipping all the dot files, and then see if the problem goes away.

  • by Dave Lasker,

    Dave Lasker Dave Lasker Aug 13, 2012 1:04 PM in response to Cimmy
    Level 1 (100 points)
    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.

  • by Hankk2,

    Hankk2 Hankk2 May 9, 2013 3:55 AM in response to Cimmy
    Level 1 (5 points)
    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.

  • by Bill Scott,

    Bill Scott Bill Scott May 14, 2013 7:48 AM in response to Dave Lasker
    Level 6 (11,449 points)
    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.

  • by Karthoo,

    Karthoo Karthoo Jun 9, 2013 6:36 AM in response to Bill Scott
    Level 1 (0 points)
    Jun 9, 2013 6:36 AM in response to Bill Scott

    This message on XQuartz-dev mailing list helped me come to the conclusion that my /Library/LaunchAgents directory was group writable. This

     

    sudo chmod 755 /Library/LaunchAgents

     

    fixed the problem of the XQuartz agent not starting for me.

  • by espenfromåsgreina,

    espenfromåsgreina espenfromåsgreina Jun 18, 2013 10:51 PM in response to Karthoo
    Level 1 (0 points)
    Jun 18, 2013 10:51 PM in response to Karthoo

    Thanx for this tip!

     

    This solved my problem:

    1. sudo chmod 755 /Library/LaunchAgents
    2. launchctl unload -w /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
    3. launchctl load -w /Library/LaunchAgents/org.macosforge.xquartz.startx.plist
    4. reboot
  • by HishamMalik,

    HishamMalik HishamMalik Jul 22, 2013 2:54 PM in response to Cimmy
    Level 1 (0 points)
    Jul 22, 2013 2:54 PM in response to Cimmy

    In my case, I did not have X11 server installed on the remote CentOS server machine. All I had to do was run the command:

     

    yum -y groupinstall "X Window System"

     

    and reinitiate the remote ssh access.

  • by marina_rpz,

    marina_rpz marina_rpz Dec 11, 2013 11:21 AM in response to Frank Caggiano
    Level 1 (0 points)
    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!!!

  • by ardenton,

    ardenton ardenton Jan 11, 2014 10:45 AM in response to Cimmy
    Level 1 (0 points)
    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.

  • by ardenton,

    ardenton ardenton Jan 15, 2014 4:29 PM in response to ardenton
    Level 1 (0 points)
    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.).

  • by AshkanRafiee,

    AshkanRafiee AshkanRafiee Feb 21, 2016 6:10 PM in response to Cimmy
    Level 1 (0 points)
    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

Previous Page 2 of 3 last Next