rbenv: can't rehash, .rbenv shims exists, but it doesn't

I’m using a shared install of rbenv as per https://github.com/sstephenson/rbenv/wiki/shared-install-of-rbenv

In general, it was working, when I only had one ruby installed. But now I installed a jruby too, and have set it using rbenv shell.

And for some reason rbenv rehash ain’t working when jruby is active.

bash-3.2$ rbenv rehash
rbenv: cannot rehash: /usr/local/rbenv/shims/.rbenv-shim exists
bash-3.2$ ls -l /usr/local/rbenv/shims/.rbenv-shim
ls: /usr/local/rbenv/shims/.rbenv-shim: No such file or directory

Any ideas of where I should start troubleshooting here?

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 27 (8 by maintainers)

Commits related to this issue

Most upvoted comments

According to the source of rbenv-rehash, this file should only exist as long as an rbenv-rehash is running. So you can delete it if you’re positive there ain’t no rbenv-rehash running and try again.

Also seeing this problem. I’m using rbenv 0.4.0 on CentOS 6.3 in a Vagrant VM, with rbenv installed for all users (as root) in /usr/local. rbenv rehash will fail saying the lock file exists when it doesn’t unless the shims directory is world-writable:

$ whoami
vagrant
$ pwd
/usr/local/rbenv
$ ls -l | grep shims
drwxr-xr-x 2 root root  4096 Mar  6 19:39 shims
$ ls -a shims | grep .rbenv-shim
$ rbenv rehash
rbenv: cannot rehash: /usr/local/rbenv/shims/.rbenv-shim exists
$ sudo chmod o+w shims
$ rbenv rehash
$ 

@lucaspottersky: Does the /opt/rbenv/shims/.rbenv-shim exist? Does it get fixed when you remove it?

I had this same problem (also using shared install) and these steps ultimately solved the problem for me:

Making sure the ~/.profile contained the right things:

export RBENV_ROOT=/usr/local/rbenv
# these next are as usual for rbenv
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"

And then followed the steps from this SO answer (starting with obliterating existing folders): http://stackoverflow.com/a/11146496/21217

Actually here are the steps for posterity:

I was having the same issue. One hint was that rbenv exec bundle exec command worked and that rbenv exec bundle install --path vendor/bundle worked, but their none prefixed equivalents failed.

I wiped my ~/.rbenv, ~/.gem Gemfile.lock and vendor/bundle a few times trying to start fresh. Once these were cleaned away I tried the following:

rbenv install 1.9.3-p194
rbenv rehash # for paranoia's sake
rbenv global 1.9.3-p194
gem env # to check that everything was pointing at 1.9 and not the system
gem install --no-ri --no-rdoc bundler
rbenv rehash # necessary to load up the bundle executable
bundle --path=vendor/bundle

and it worked!

I think the important thing, since I tried this a few times, is to remove the .gem file from your home directory. It seems to get in the way.