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

'rbenv rehash' creating shim for uninstalled gem (vagrant) #388

Closed
leucos opened this issue May 8, 2013 · 19 comments
Closed

'rbenv rehash' creating shim for uninstalled gem (vagrant) #388

leucos opened this issue May 8, 2013 · 19 comments

Comments

@leucos
Copy link

leucos commented May 8, 2013

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 ?

@leucos
Copy link
Author

leucos commented May 8, 2013

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.

@tonchis
Copy link

tonchis commented May 16, 2013

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!

@mislav
Copy link
Member

mislav commented May 17, 2013

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

@tonchis
Copy link

tonchis commented May 17, 2013

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.

@mislav
Copy link
Member

mislav commented May 17, 2013

Any plugins? rbenv hooks rehash

@tonchis
Copy link

tonchis commented May 17, 2013

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

@tonchis
Copy link

tonchis commented May 17, 2013

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

@tonchis
Copy link

tonchis commented May 17, 2013

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!

@mislav
Copy link
Member

mislav commented May 17, 2013

Boom! Resolved. Nice work

@mislav mislav closed this as completed May 17, 2013
@leucos
Copy link
Author

leucos commented May 17, 2013

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 #388 (comment)).

Thanks !

@tonchis
Copy link

tonchis commented May 17, 2013

@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

@mislav
Copy link
Member

mislav commented May 18, 2013

@leucos Any plugins? rbenv hooks rehash

@mislav mislav reopened this May 18, 2013
@leucos
Copy link
Author

leucos commented May 18, 2013

@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 :(

@mislav
Copy link
Member

mislav commented Jun 5, 2013

@leucos No prob! Glad to have this solved.

@mislav mislav closed this as completed Jun 5, 2013
@phoet
Copy link

phoet commented Aug 12, 2013

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

@audionerd
Copy link
Contributor

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 Purple-Devs/rbenv-binstubs#6

@pbmolini
Copy link

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.

@fro
Copy link

fro commented Apr 12, 2016

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

@fro
Copy link

fro commented Apr 12, 2016

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

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

No branches or pull requests

7 participants