I'm trying to get a compile command (rake cucumber) to run with a specific ruby version on my Mac OS X system, I use rvm to do this currently in the terminal. My ~/.MacOSX/environment.plist has the correct path in it, but emacs insists on prepending to this path and therefore making it useless. I've also tried:
(when (equal system-type 'darwin)
(setenv "PATH" (concat "/Users/fearoffish/.rvm/bin:/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin:/Users/fearoffish/.rvm/bin"))
(push "/Users/fearoffish/.rvm/bin" exec-path)
(push "/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin" exec-path)
(push "/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin" exec-path)
(push "/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin" exec-path)
(push "/Users/fearoffish/.rvm/bin" exec-path))
It was the desperate attempt of an emacs beginner to get what I wanted. It still prepends in front of it, so my path ends up being:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fearoffish/.rvm/bin:/Users/fearoffish/.rvm/rubies/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249/bin:/Users/fearoffish/.rvm/gems/ruby-1.8.7-p249%global/bin
I don't want /usr/bin and others prepending, I want my path first and the emacs prepended path to be at the end, I reckon this would fix my problem.
I test this by simply opening Aquamacs and running meta-x compile
and then echo $PATH
.
Any ideas?
It worked for me with two things.
First I followed sanityinc advice
I still had a problem with compile commands. Valko Sipuli is right there was a problem involving path_helper.
I commented the corresponding line in /etc/profile and it did not help. Problem still there. I don't use bash but zsh. Digging a little I found /etc/zshenv. This file also calls path_helper.
After commenting the path_helper section in /etc/zshenv my path is finally correct
A small modification to the solution by sanityinc (couldn't find a way to enter it in the comments above -- is that just me?)
-l
option to the shell to force a login shell (which reads.profile
or.bash_profile
), rather than an interactive shell (which only reads.bashrc
).Modified code:
I don't have a Mac, so I cannot test this directly, but this can all be found in the *info* page Interactive Inferior Shell.
When you start a shell in Emacs, the process that gets spawned is the program in the Emacs variable
explicit-shell-file-name
(and if that isnil
, the environment variablesESHELL
andSHELL
are used).It then sends the contents of
~/.emacs_*shellname*
(e.g. if your shell iscsh
, then~/.emacs_csh
would be sent over. Also, the appropriate .rc files forcsh
program is sourced, so you can update that as well (in my case.cshrc
). Additionally, you can wrap customizations in the .rc file with a check for the environment variableINSIDE_EMACS
(which which Emacs sets before it runs a shell).You need to update those files to change the path in the shell, not the Emacs variable
exec-path
.exec-path
- which is just a list of directories Emacs uses to find executable programs. The behavior of the executables are not affected by changes toexec-path
.I find the environment.plist scheme on Macs pretty ugly, so I use the following snippet, which assumes you want Emacs to use the same PATH that you see in your Terminal.app:
(This works for me in Emacs 23; haven't tried it in other versions, but I'd expect it to work.)
try this maybe. replace path string with yours.
(add-to-list 'load-path "~/opt/swank-clojure/src/emacs")
As far as I observed, Emacs takes the path variable from the shell it is launched from, so one solution is to change $PATH in the shell before you launch Emacs.
One other approach I used, which is more flexible, is to use a Makefile and append a "source ~/script_that_set_path" in front of each make commands you have.