问题
I use plain Vim with ruby support on Lion (installed by gist). I am using ruby with rbenv so my path looks like /users/me/.rbenv/shims:.....
From within vim the path is
:!echo $PATH
> usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fb/.rbenv/shims:....
Even I can create and modify an environment variable:
:let $PATH = "/bar:/foo"
:!echo $PATH
> /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/foo:/bar
paths remains starting with /usr/bin.
So how can I access my ruby 1.9.3 in ~/.rbenv/shims instead the system ruby in /usr/bin ?
回答1:
This is a known problem introduced by Apple in OS X 10.5 Leopard.
If you are using Bash or Zsh and are using non-interactive shells, you are affected.
Running sudo chmod ugo-x /usr/libexec/path_helper
will fix you up, but you should take a look at the article to see why.
回答2:
rvm also has this problem. If zsh is your default shell when it starts /etc/zshenv
gets executed.
This executes /usr/libexec/path_helper
. That sets up the path based on the contents /etc/paths
and /etc/paths.d/
.
The faq for rvm mentions moving /etc/zshenv
to /zsh/zshrc
. I did this and it removed the /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
from the start of my path in macvim.
回答3:
I did'n t set the shell
option in .vimrc, so that it was automatically set to /bin/zsh
.
Then I found out that I hab a dublicate initialisation of rbenv: in my .zshrc. I removed the initialisation end $PATH extensioin in .zshrc
because that was already handled by the oh-my-zsh rbenv plugin.
Even after that cleanup, the $PATH mangeling still happening so :!echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fb/.rbenv/shims:/Users/fb/.rbenv/bin:/Users/fb/bin:/usr/local/sbin:/usr/games
Setting :set shell=/bin/bash
was what helped me, as i can live with bash in my vim: :!echo $PATH
/Users/fb/.rbenv/shims:/Users/fb/.rbenv/bin:/Users/fb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/Users/fb/Dropbox/local/bash
回答4:
In your ~/.bashrc (or whatever shell you're using) file, add the following line:
PATH=/home/me/.rbenv/shims:${PATH}
and then run source ~/.bashrc
(or .zshrc or whatever shell you're using!)
回答5:
This can be fixed by just adding
PATH=/home/me/.rbenv/shims:${PATH}
to
/etc/zshenv
回答6:
I don't use mac or zsh (I am on linux), however I ran into this problem when I ran gvim from the MATE Menu.
I solved it by adding this to my .vimrc:
if $PATH !~ "\.rbenv"
let $PATH="/home/username/.rbenv/shims:/home/username/.rbenv/bin:" . $PATH
endif
This avoids setting it if you run vim from a terminal, otherwise the rbenv paths would be included twice.
I tried setting the application to run via a terminal, but that didn't help.
回答7:
yes on OS X it's the bash_profile that gets sourced when opening a new console window whereas on Linux it's your bashrc
来源:https://stackoverflow.com/questions/9853584/how-to-use-correct-ruby-in-vim-how-to-modify-path-in-vim