MATLAB: Does MATLAB 7.8 (R2009a) fail to launch if X11 is not already running

MATLAB

I installed MATLAB 7.8 (R2009a) on a Macbook Pro running OS X 10.5.6. When I launch MATLAB, it fails if X11 is not already running. This behavior is unexpected as MATLAB 7.7 (R2008b) and earlier versions auto start X11.

Best Answer

Mac OS X 10.5 uses x.org's X11 which takes advantage of a new system startup feature called launchd, which will automatically launch applications and daemons on demand. MATLAB will automatically launch the X11 server when an X11 library is loaded and an X11 call is made, using an automatically assigned DISPLAY value (per logged-in user), rather than the traditional local DISPLAY value of ':0'.
Under Mac OS X 10.5, your DISPLAY environment variable should have a value that looks similar to this, beginning with /tmp/launch:
/tmp/launch-h40Qzv/:0
Mac OS X 10.5 and X11 R7 make this assignment for you (and for MATLAB), so neither you nor MATLAB should be specifying DISPLAY any more.
If MATLAB is failing to launch without X11 already being launched, the most common cause of this is a startup shell file (or environment file) which is changing the value for DISPLAY (usually to ':0'). The value of ':0' only happens to succeed when X11.app is launched as a Startup Items item (e.g., by your user account at login time).
Look in the following potential locations and files for possible places where DISPLAY may be shadowing the system-defined DISPLAY environment variable (where ~ is your home folder):
~/.bashrc
~/.cshrc
~/.MacOSX/environment.plist
~/.xinitrc
If you know of other shell initialization files, check those as well.
If for some reason you must specify ':0' (or if you are unable to find where it's getting redefined), you can add X11.app to your Startup Items, which will enable ':0' to continue working as it did before.