Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh command hash table is stale with system ruby #119

Closed
bricestacey opened this issue Oct 11, 2011 · 8 comments
Closed

zsh command hash table is stale with system ruby #119

bricestacey opened this issue Oct 11, 2011 · 8 comments
Labels
Milestone

Comments

@bricestacey
Copy link

I have a zsh script to setup dev environments that create tmux sessions and windows. (see http://pastie.org/2643820)

Occasionally, a tmux window's zsh's command hash would still be pointing to the system ruby.

[master][~/code/ezpz] hash | grep ruby=
jruby=/Users/brice/.rbenv/shims/jruby
ruby=/usr/bin/ruby

[master][~/code/ezpz] env | grep PATH
PATH=/Users/brice/.rbenv/shims:/Users/brice/.rbenv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/brice/.rbenv/shims:/Users/brice/.rbenv/bin:/opt/local/bin:/usr/local/git/bin

[master][~/code/ezpz] ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

[master][~/code/ezpz] which ruby
/usr/bin/ruby

[master][~/code/ezpz] /Users/brice/.rbenv/shims/ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]

Would it be a good idea to maybe include a call the builtin rehash after rbenv-init has been run? This seems to have solved my problem. I just do the following in .zshrc

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
builtin rehash
@bricestacey
Copy link
Author

Here is some background information I found on this issue from rvm's history: rvm/rvm@f6473f2

@josh
Copy link
Contributor

josh commented Oct 12, 2011

Seems like zsh really needs rehash after any calls to rbenv rehash.

Theres a few issues. rehash is specific to zsh so we just can't add a call to our scripts. We'd need to detect zsh which we're already doing a bad job already. See #59.

Also rbenv rehash spawns a subprocess so running rehash there won't affect your current shell.

So I don't really see a good way to approach this issue. RVM is able to just call out to rehash since its one big ass shell function.

@bricestacey
Copy link
Author

hash -r is a builtin for both bash and zsh to empty the hash.

I am an unsophisticated shell user so I'm afraid I have little more to add other than these observations.

@sstephenson
Copy link
Contributor

Josh, seems like we could force this by calling hash -r every time our rbenv function runs.

@dtuite
Copy link

dtuite commented Nov 22, 2011

I think I'm having the same problem with zsh. I can't seem to use rbenv's ruby no matter what I try.

rbenv global
=> 1.9.3-p0

rbenv local
=> 1.9.3-p0

which ruby
=> /usr/bin/ruby

hash | grep ruby=
ruby=/usr/bin/ruby

I have the following in my .zshrc

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
builtin hash -r

I don't actually know what the "hash" is or what rehash does but I'm sure I've typed it at least 20 times at various stages! Nothing seems to work.

@freshfey
Copy link

@dtuite not sure if this solves your problem, but I had two export PATH=... lines in my .zshrc, deleting one solved the problem for me (without the builtin hash -r)

@dtuite
Copy link

dtuite commented Mar 15, 2012

That could be it all right. I have multiple export PATH=.. lines in my .zshrc also. Unfortunately I can't test at the moment because I'm back on RVM.

Thanks for the tip though.

@thomasklemm
Copy link

Just installed a gem with an executable for the first time after switching to zsh. With bash all I had to do was run rbenv rehash sometimes to get access to the executable. In zsh however, this did not work. I also use oh-my-zsh with the rbenv plugin.

Solved it by first removing the oh-my-zsh rbenv plugin from ~/.zshrc, doing an rbenv rehash, then running hash -r. So it might be a good option to always run hash -r after rbenv rehash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants