OS X Leopard and X11

Here are two of the biggest problems I’ve come across in using X11 with SSH connections, and how to get around them.

OS X employs a combination of the X.org package and Xquartz, a component included in Mac’s X (or X11) to help it run on OS X. Getting these two to work in concert once one of them, or the operating system itself, has been upgraded can be frustrating.

It used to be the case that in order to get X working remotely from an OS X machine, you needed to set your DISPLAY system variable to something that made sense to non-Mac systems (such as “localhost:0“). But if you’re running the latest version of Leopard (10.5.3), X11 (2.2.1), and Xquartz (1.3.0), doing so is not only unnecessary, but it can keep your X sessions from launching properly. If you’re seeing errors like this on your side when launching an X application:

Error: Can't open display: localhost:0

… or like this on a remote host:

connect localhost port 6000: Connection refused

… it’s probably the case that you need to un-set your DISPLAY variable. Try removing any commands that export a DISPLAY value to your environment (such as ‘export DISPLAY=something‘), logging out of your current sessions, and see if you can successfully launch your X app.  You’ll also need to not launch X11 explicitly: let the OS launch it for you on its own when you request an X application (test by running xterm or xclock from a terminal).

Inversely, in the version of X native to OS X 10.5.2, you may see a wacky-looking error like the following when launching an X application on a remote host:

/tmp/launch-rkTZqq/: unknown host. (nodename nor servname provided, or not known)
X connection to localhost:39.0 broken (explicit kill or server shutdown).

If you check your local DISPLAY variable (with echo $DISPLAY), you may see an equally strange value:


Essentially, you need to do the exact inverse of the above fix: explicitly set the value of DISPLAY in your environment before launching an X app on a remote host:

export DISPLAY=localhost:0

You can do this as a command, or by adding this line to a profile (such as ~/.bash_profile) so that it gets read automatically at the start of each session.  In addition, you may need to explicitly launch X11 (Applications -> Utilities -> X11, or search Spotlight for “X11″) before launching an X application.

Why two successive versions of the same software require such polar fixes is beyond me! But at least now you may know how to deal with the problem in your particular environment.

If you need additional help or troubleshooting information, sao1′s Leopard and X11 blog is a great resource.

About these ads

One thought on “OS X Leopard and X11

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s