I recently installed Ruby 1.8.7 in /usr/local. I have Ruby 1.8.6 installed via MacPorts in /opt/local. I couldn’t understand why TextMate’s Ruby bundle was running Ruby 1.8.7 even though my bash .profile was setting PATH correctly; i.e. /opt/local/bin was before /usr/local/bin.
Several people in the #textmate IRC channel helped out, including Allan, the creator of TextMate, the popular text editor for the Mac. These are the must-read resources:
The key thing I learned is that TextMate has two execution contexts: the “bash execution environment” and the “shebang execution environment.” Each context acquires its PATH in a different way.
Examine the PATHs
Here is how you can see the value of PATH for each context:
# bash execution environment
echo “$PATH”
# Highlighting the above line and pressing CTRL-R…
# …will give something like:
/Applications/TextMate.app/Contents/SharedSupport/Support/bin/CocoaDialog.app/Contents/MacOS: /Users/djwonk/bin: /opt/local/bin: /opt/local/sbin: /usr/local/mysql/bin: /usr/local/bin: /Users/djwonk/bin: /opt/local/bin: /opt/local/sbin: /usr/local/mysql/bin: /usr/bin:/bin:/usr/sbin: /sbin: /usr/local/bin: /usr/X11/bin: /Applications/TextMate.app/Contents/SharedSupport/Support/bin
# shebang execution environment
#!/bin/sh
echo “$PATH”
# Highlighting the two above lines and pressing CTRL-R…
# …will give something like:
/usr/local/bin: /Users/djwonk/bin: /opt/local/bin: /opt/local/sbin: /usr/local/mysql/bin: /usr/bin: /bin: /usr/sbin: /sbin: /usr/local/bin: /usr/X11/bin
(Note: I added spaces between : and / purely for blog formatting. That way the lines wrap at sensible places. Your actual results won’t have these spaces, and you shouldn’t have any extra spaces in your PATHs.)
My bash execution environment was fine. However, my shebang execution environment was incorrect: /usr/local/bin was in front of /opt/local/bin.
The Solution
The solution for me was to create the ~/.MacOSX/environment.plist file with the desired path. In my case it was:
{ PATH = “/Users/djwonk/bin: /opt/local/bin: /opt/local/sbin: /usr/local/mysql/bin: /usr/bin: /bin:/usr/sbin: /sbin:/usr/local/bin: /usr/X11/bin”; }
One Comment
You may also use
printf “%s\n” “${PATH}” | tr ‘:’ ‘\n’
instead of using
echo “$PATH”
(i think i saw that on codesnippets by joyent)
Post a Comment