11

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 ?

fbehrens
  • 6,115
  • 2
  • 19
  • 22

7 Answers7

30

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.

Edward Ocampo-Gooding
  • 2,782
  • 1
  • 23
  • 29
  • 3
    This solution works perfectly. But I found the suggestion provided by tpope's [vim-rbenv](https://github.com/tpope/vim-rbenv#faq) to be a better one because it still enables the execution of the `path_helper` on interactive shells. Simply `sudo mv /etc/zshenv /etc/zshrc` and vim says Yay! – Tiago Mar 28 '14 at 19:45
  • 1
    This really can't get enough upvotes. This is the second time I've come here because how in the world could anyone remember they need to do this when setting up an environment. – Chris Nicola Apr 16 '15 at 20:43
  • I get `chmod: Unable to change file mode on /usr/libexec/path_helper: Operation not permitted` error when I run this command. Any pointers. – Zuhaib Feb 21 '17 at 22:14
  • @Zuhaib are you using `sudo`? – Edward Ocampo-Gooding Mar 20 '17 at 02:13
  • @EdwardOcampo-Gooding I am using sudo and I also have Zuhaib's issue. – azureai Feb 21 '20 at 21:23
5

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.

PaddyDwyer
  • 475
  • 3
  • 8
  • I altered `/etc/paths` and that worked for me. **Thank you!** This is great to know. – duma Mar 04 '13 at 15:12
4

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

fbehrens
  • 6,115
  • 2
  • 19
  • 22
2

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!)

Paul Simpson
  • 2,504
  • 16
  • 28
  • If you put that in `~/.bash_profile` you won't have to run the source command (it will automatically run that command every time you start a new shell) – Jwosty Mar 24 '12 at 17:21
  • True - didn't think of that. Though you'll only need to run the source command once for each shell you had open when you edited ~/.bashrc. In my head I was translating from zsh to bash - I really just wanted to tell him to put it in his ~/.zshrc :) – Paul Simpson Mar 24 '12 at 17:33
  • Thanks for answering. I use zsh and have no .bashrc nor .bash_profile. For testing i created them, but it doesn't help. I use zsh and my path is set correct both in Terminal and Iterm2. – fbehrens Mar 26 '12 at 20:46
  • 1
    in zsh `echo $PATH` >/Users/fb/.rbenv/shims:... in `vim` `:set shell?` >shell=/bin/zsh, `:echo $PATH` >/Users/fb/.rbenv/shims:... but `:!echo $PATH` >/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fb/.rbenv/shims:... and so `:!ruby -v`>ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] and not the fancy 1.9.3, :( ???? – fbehrens Mar 26 '12 at 20:55
  • Based on the installation instructions (https://github.com/sstephenson/rbenv#section_2), it looks like you should have /home/me/.rbenv/bin in your path, not /home/me/.rbenv/shims. You could also give rvm a shot - I have no issues with it on Lion (https://rvm.beginrescueend.com/) – Paul Simpson Mar 26 '12 at 23:28
1

This can be fixed by just adding

PATH=/home/me/.rbenv/shims:${PATH}

to

/etc/zshenv
bitmask
  • 32,434
  • 14
  • 99
  • 159
trnc
  • 20,581
  • 21
  • 60
  • 98
1

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.

Jordan Morris
  • 2,101
  • 2
  • 24
  • 41
0

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

phildobbin
  • 814
  • 8
  • 9