Rbenv: 'rbenv rehash' creating shim for uninstalled gem (vagrant)

Created on 8 May 2013  路  19Comments  路  Source: rbenv/rbenv

Since vagrant is not a gem anymore (sigh :|), I tried to remove the gem and use the installer (Archlinux/AUR) :

$ gem uninstall vagrant
Remove executables:
    vagrant

in addition to the gem? [Yn]  Y
Removing vagrant
Successfully uninstalled vagrant-1.0.7
$ yaourt -Suy vagrant
...
$ rbenv rehash
$ which vagrant
/home/user/.rbenv/shims/vagrant
$ vagrant
rbenv: vagrant: command not found
$ find ~/.rbenv -name '*vagrant*'
/home/user/.rbenv/shims/vagrant
$ rm /home/user/.rbenv/shims/vagrant
$ find ~/.rbenv -name '*vagrant*'
$ rbenv rehash
$ find ~/.rbenv -name '*vagrant*'
/home/user/.rbenv/shims/vagrant
$ gem list vagrant

*** LOCAL GEMS ***
$

Everytime I run rbenv rehash, the vagrant shim is created. However, the vagrant gem is not installed.

Any clue on what's going wrong here ?

Most helpful comment

rbenv makes shims for files found in $RBENV_ROOT/versions/*/bin directories. Can you check these directories for a vagrant executable?

ls "$(rbenv root)"/versions/*/bin/vagrant

All 19 comments

Mmmh, I have vendorized gems in few places with bundler. It seems that rbenv is parsing vendor/ directories it's aware of and installs shims for gems found.
Correct me if I'm wrong, but I'm not sure it's ok to install a shim and make it available for use outside the project directory in a vendorized setup.

I'm having the same problem and don't even have vagrant installed

$ vagrant
rbenv: vagrant: command not found
$ gem list | ack "vagrant"
$ gem uninstall vagrant # for paranoia's sake
$ rbenv rehash
$ vagrant
rbenv: vagrant: command not found
$ which vagrant
/Users/tonchis/.rbenv/shims/vagrant
$ rm -rf /Users/tonchis/.rbenv/shims/vagrant
$ vagrant
zsh: command not found: vagrant
$ rbenv rehash
$ vagrant
rbenv: vagrant: command not found

Let me know if I can help you any further by including more information!

rbenv makes shims for files found in $RBENV_ROOT/versions/*/bin directories. Can you check these directories for a vagrant executable?

ls "$(rbenv root)"/versions/*/bin/vagrant

Here you go:

$ ls /Users/tonchis/.rbenv/versions/*/bin
coderay erb     gem     irb     rake    rdoc    ri      ruby    testrb

Also, I only have one ruby version at the moment.

Any plugins? rbenv hooks rehash

Yup, two:

$ ls /Users/tonchis/.rbenv/plugins
rbenv-gemset ruby-build
$ rbenv hooks rehash
/Users/tonchis/.rbenv/plugins/rbenv-gemset/etc/rbenv.d/rehash/gemset.bash
$ vagrant
rbenv: vagrant: command not found

# also in case you might need it
$ gem env path
/Users/tonchis/.rbenv/versions/1.9.3-p392/gemsets/global

Ok, so I think I found the culprit:

$ ls .rbenv/versions/*/gemsets/*/bin/* | ack "vagrant"
.rbenv/versions/1.9.3-p392/gemsets/api-server/bin/vagrant

Solved! Heads up @leucos.

$ cd <api-server dir>
$ gem env path
/Users/tonchis/.rbenv/versions/1.9.3-p392/gemsets/api-server:/Users/tonchis/.rbenv/versions/1.9.3-p392/gemsets/global
$ gem uninstall vagrant
Remove executables:
    vagrant

in addition to the gem? [Yn]  Y
Removing vagrant
Successfully uninstalled vagrant-1.0.0
$ rbenv rehash
$ vagrant
zsh: command not found: vagrant

So basically if I'm using rbenv-gemsets, rbenv rehash builds shims with the binaries living in "$(rbenv root)"/versions/*/gemsets/*/bin as well.

Thanks a lot @mislav!

Boom! Resolved. Nice work

I'm sorry, it is not solved.
If you look carefully at the first comment in this issue :

$ find ~/.rbenv -name '*vagrant*'
/home/user/.rbenv/shims/vagrant
$ rm /home/user/.rbenv/shims/vagrant
$ find ~/.rbenv -name '*vagrant*'
$ rbenv rehash
$ find ~/.rbenv -name '*vagrant*'
/home/user/.rbenv/shims/vagrant

TL;DR : I have nothing containing 'vagrant' in it's name under ~/.rbenv besides the shim itself, that rbenv rehash recreates all the time.

The only place I have it is in some vendorized gems (see second comment https://github.com/sstephenson/rbenv/issues/388#issuecomment-17602410).

Thanks !

@mislav is it possible for hooks to live outside rbenv root? That could explain @leucos symptom. For what I understand, shims are made here or through hooks

@leucos Any plugins? rbenv hooks rehash

@mislav / @tonchis : thanks for the heads up. I think you nailed it :

~/.rbenv/plugins/bundler/etc/rbenv.d/rehash/bundler.bash
~/.rbenv/plugins/rbenv-gemset/etc/rbenv.d/rehash/gemset.bash

I seems that bundler.bash keeps a list of Gemfile it was invoked for, and rebuilds shims for them. Since I use bundler and vendorized a project which had the vagrant gem, it was rebuilding a shim everytime.

So it's solved too here. Thanks !

EDIT: And sorry for blaming rbenv in the first place :(

@leucos No prob! Glad to have this solved.

@mislav thx, helped me a lot. had a similar issue with heroku binary

I had a similar issue where rbenv rehash was generating a vagrant shim despite the vagrant gem being removed on my system.

The issue in my case was due to the rbenv-binstubs plugin, which keeps references to projects in a ~/.rbenv/bundles file which it uses to automatically rehash. After reviewing all the Gemfile's in folders referenced by ~/.rbenv/bundles, I finally tracked down a reference to the old vagrant gem. Deleted that line from ~/.rbenv/bundles and all was well.

Related: the feature in rbenv-binstubs which creates these shims https://github.com/ianheggie/rbenv-binstubs/pull/6

Since this is the only place where people talk about this issue, I add my experience.
I had the same issue with heroku and I solved it by manually uninstalling the heroku gem from all the ruby installations on my machine. So, for example

rbenv local 2.1.2
gem uninstall heroku
rbenv local 1.9.3-p547
gem uninstall heroku

and so on...
finally a rbenv rehash removed the heroku shim.

Same problem here but I can't get rid of it.

Here's what I have found so far:

$ which heroku
/Users/fro/.rbenv/shims/heroku

$ rbenv versions
* system (set by /Users/fro/.rbenv/version)
  1.9.3-p125
  1.9.3-p448
  2.0.0-p0
  2.2.0
  2.2.0-preview1

$ rbenv local 1.9.3-p125
$ gem uninstall heroku
INFO:  gem "heroku" is not installed

$ rbenv local 1.9.3-p448
$ gem uninstall heroku

$ rbenv local 2.2.0-p0
rbenv: version `2.2.0-p0' not installed

$ rbenv local 2.0.0-p0
$ gem uninstall heroku

$ rbenv local 2.0.0
rbenv: version `2.0.0' not installed

$ rbenv local 2.2.0
$ gem uninstall heroku

$ rbenv local 2.2.0-preview1
$ gem uninstall heroku

$ gem uninstall heroku --all
$ sudo gem uninstall heroku --all
Password:

$ rbenv hooks rehash
/usr/local/Cellar/rbenv-gemset/0.5.8/etc/rbenv.d/rehash/gemset.bash

$ rbenv rehash

$ which heroku
/Users/fro/.rbenv/shims/heroku

I can't get rid of /Users/fro/.rbenv/shims/heroku.

Please someone can explain what I've missed?
Thank you

Ohhh... reading all the comments again, I have found that @leucos solution was precisely what I needed:

$ ls .rbenv/versions/*/gemsets/*/bin/* | grep "heroku"
.rbenv/versions/1.9.3-p448/gemsets/project1-gems/bin/heroku
.rbenv/versions/1.9.3-p448/gemsets/project2-gems/bin/heroku
.rbenv/versions/2.2.0/gemsets/project3-gems/bin/heroku
.rbenv/versions/2.2.0/gemsets/project4-gems/bin/heroku
$ rm .rbenv/versions/1.9.3-p448/gemsets/project1-gems/bin/heroku
$ rm .rbenv/versions/1.9.3-p448/gemsets/project2-gems/bin/heroku
$ rm .rbenv/versions/2.2.0/gemsets/project3-gems/bin/heroku
$ rm .rbenv/versions/2.2.0/gemsets/project4-gems/bin/heroku

No more automatic shims/heroku for me:

$ which heroku
/usr/local/bin/heroku
Was this page helpful?
0 / 5 - 0 ratings