views:

411

answers:

1

I am running bash in emacs on osx and its pulling gems from a different place then terminal.app

in bash:

which gem
/usr/bin/gem

in terminal:

which gem
/opt/local/bin/gem

How do I change the bash to match terminals?

+4  A: 

I'm guessing the $PATH is different in the emacs bash shell. You can check it out by running this command in each.

echo $PATH

This is the lookup path used to find commands. You need to include /opt/local/bin into this.

export PATH="/opt/local/bin:$PATH"

Place that line inside of your ~/.bashrc file and it should be picked up by bash when used in emacs (unless it is being run under a different user or something).


Update:

As Singletoned mentioned in the comments, Emacs will not load the ~/.bash_profile or ~/.profile but the Terminal will. This file likely already contains this PATH definition causing the two to have a different behavior.

I recommend moving the PATH definition from bash_profile file into bashrc. However Terminal will not load bashrc if bash_profile exists.

The solution is to add this to ~/.bash_profile.

if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

You can then move everything else into bashrc which will be included into bash_profile.

ryanb
Awesome it worked, this problem has bothered me for so long.
dMix
Just to clarify this slightly, when Emacs starts a bash session it will run .bashrc, but not .profile or .bash_profile. Terminal runs .bashrc and one of .profile or .bash_profile. That's why you had different paths.
Singletoned
Thanks Singletoned, updated the answer to reflect this.
ryanb