postmodern / chruby

Changes the current Ruby
MIT License
2.87k stars 190 forks source link

vim not loading correct ruby version #382

Closed elle closed 6 years ago

elle commented 7 years ago

This is a similar problem to https://github.com/postmodern/chruby/issues/196 but for some reason, I cannot get vim to load correct Ruby version.

My dotfiles are are: https://github.com/elle/dotfiles But for summary, I have the following set up:

# ~/.zshrc
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh

# ~/.vimrc
set shell=$SHELL\ -l

I actually needed to move sourcing chruby to ~/.zshenv to be able to see it in vim.

I also: sudo mv /etc/zshenv /etc/zprofile

Still, in iTerm, I get:

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]

...but in vim, I get:

:!ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin14] 

Lastly, when checking the $PATH in vim, I get:

:!echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/em/.gem/ruby/2.3.1/bin:/Users/em/.rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/bin:/Users/em/.rubies/ruby-2.3.1/bin:/Users/em/bin

And when I try to run a test file via vim-test plugin, I get the following error:

`validate_ruby!': Your Ruby version is 2.3.3, but your Gemfile specified 2.3.1 (Bundler::RubyVersi
onMismatch)

Any ideas why this is not working for me?

postmodern commented 7 years ago

Something appears to be moving /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin to the front of $PATH, when it should be at the end.

havenwood commented 7 years ago

@elle It looks like you modified PATH in your ~/.zshrc to appease Homebrew. I'd suggest removing the PATH="...:$PATH" line from your ~/.zshrc file and instead reordering the lines in your /etc/paths file to something like:

/usr/local/bin
/usr/local/sbin
/usr/bin
/usr/sbin
/bin
/sbin

Then rerun brew doctor and make sure Homebrew is happy with your new PATH order.

havenwood commented 6 years ago

Closing this since the cause of the issue was determined to be manual path munging in the ~/.zshrc file.

As mentioned above, a nice fix is to reorder /etc/paths instead of munging PATH in the dotfile.