rbenv icon indicating copy to clipboard operation
rbenv copied to clipboard

cannot find `--user-install`d gem executable

Open longspell opened this issue 5 years ago β€’ 13 comments

I have the following ruby versions installed via rbenv, 2.0.0-p648, 2.6.3 and 2.6.5 which both 2.6 versions have rubocop installed:

Results when using 2.6.3:

$ rbenv versions
  system
  2.0.0-p648
* 2.6.3 (set by /Users/longspell/.ruby-version)
  2.6.5
$ gem info rubocop

*** LOCAL GEMS ***

rubocop (0.80.1, 0.75.1)
    Authors: Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama
    Homepage: https://github.com/rubocop-hq/rubocop
    License: MIT
    Installed at (0.80.1): /Users/longspell/.gem/ruby/2.6.0
                 (0.75.1): /Users/longspell/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0

    Automatic Ruby code style checking tool.
$ rubocop --version
0.80.1

Results when using 2.6.5:

$ rbenv versions
  system
  2.0.0-p648
  2.6.3
* 2.6.5 (set by /Users/longspell/test/.ruby-version)
$ gem info rubocop
Ignoring byebug-11.1.1 because its extensions are not built. Try: gem pristine byebug --version 11.1.1
Ignoring io-console-0.5.6 because its extensions are not built. Try: gem pristine io-console --version 0.5.6

*** LOCAL GEMS ***

rubocop (0.80.1)
    Authors: Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama
    Homepage: https://github.com/rubocop-hq/rubocop
    License: MIT
    Installed at: /Users/longspell/.gem/ruby/2.6.0

    Automatic Ruby code style checking tool.
$ rbenv rehash
$ rubocop --version
rbenv: rubocop: command not found

The `rubocop' command exists in these Ruby versions:
  2.6.3

Same results for solargraph. Seems to be trying to use the ~/.rbenv/versions bin instead of the ~/.gems bin path. This happens even if I am on 2.6.5 and do gem install rubocop. I've even gone so far as to gem uninstall rubocop and remove all versions from 2.6.3, but upon gem install rubocop && rbenv rehash in 2.6.5 I'm still told rubocop only exists in 2.6.3.

longspell avatar Mar 26 '20 15:03 longspell

I'm sorry you're having trouble!

Does the rubocop binary for 2.6.5 exist? Check with file `rbenv prefix 2.6.5`/bin/rubocop

If not, where does gem install place the rubocop binary if not there?

mislav avatar Mar 26 '20 16:03 mislav

Thanks for the quick reply. I nuked every copy of the gem and did another install while 2.6.5 was active. The binary appears to get installed into the ~/.gem directory:

$ rbenv version
2.6.5 (set by /Users/longspell/test/.ruby-version)
$ gem info rubocop

*** LOCAL GEMS ***

rubocop (0.80.1)
    Authors: Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama
    Homepage: https://github.com/rubocop-hq/rubocop
    License: MIT
    Installed at: /Users/longspell/.gem/ruby/2.6.0

    Automatic Ruby code style checking tool.
$ /Users/longspell/.gem/ruby/2.6.0/bin/rubocop --version
0.80.1

Should rehash be picking up the gems under ~/.gem/ruby/2.6.0/bin/?

longspell avatar Mar 26 '20 17:03 longspell

In case it's relevant, when I have 2.6.5 active:

$ gem env home
/Users/longspell/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0
$ gem env path
/Users/longspell/.gem/ruby/2.6.0:/Users/longspell/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0

longspell avatar Mar 26 '20 17:03 longspell

I resolved this by doing gem install rubocop --no-user-install in each ruby version, I now get the binary installed in both. Still wondering if the rehash was meant to be able to find the binary under ~/.gem though?

Thanks

$ find ~/.rbenv -name rubocop
/Users/longspell/.rbenv/versions/2.6.3/bin/rubocop
/Users/longspell/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/bin/rubocop
/Users/longspell/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop
/Users/longspell/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/exe/rubocop
/Users/longspell/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-13.0.1/bin/rubocop
/Users/longspell/.rbenv/versions/2.6.5/bin/rubocop
/Users/longspell/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rake-12.3.2/bin/rubocop
/Users/longspell/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/lib/rubocop
/Users/longspell/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/rubocop-0.80.1/exe/rubocop```

longspell avatar Mar 26 '20 18:03 longspell

@longspell Ah, sorry for this not being more clear: rbenv does not have support for discovering binstubs under ~/.gem. This is because discovering those binstubs isn't straightforward and we would rather not support it. You can gain support by using my plugin, but I can't attest to its quality: https://github.com/mislav/rbenv-user-gems

Running rbenv-doctor script actually warns about having --user-install in your .gemrc:

mislav avatar Mar 26 '20 19:03 mislav

Actually I'll keep this open so we can explore whether supporting this today is something more stable that could be baked into rbenv πŸ€”

mislav avatar Mar 26 '20 19:03 mislav

Full disclosure, I had a long forgotten ~/.gemrc that was setting my gem installs to the user space. πŸ˜‘

Thanks for the cordial responses and looking into this.

longspell avatar Mar 26 '20 20:03 longspell

I seem to have the same problem, even though I don't have a ~/.gemrc file. I ran these commands:

rbenv install 2.7.1
gem install rubocop:0.82.0
rbenv rehash
[10:49:17] ~  ➜ rbenv versions
  system
  2.6.3
* 2.7.1 (set by /Users/pat/.rbenv/version)
[10:49:22] ~  ➜ gem list rubocop

*** LOCAL GEMS ***

rubocop (0.82.0)
rubocop-ast (0.0.3)
[10:49:27] ~  ➜ rubocop -v
zsh: command not found: rubocop
[10:53:18] ~  ➜ file `rbenv prefix 2.7.1`/bin/rubocop
/Users/pat/.rbenv/versions/2.7.1/bin/rubocop: cannot open `/Users/pat/.rbenv/versions/2.7.1/bin/rubocop' (No such file or directory)

When I uninstall Rubocop, it asks me if I want to remove the executable:

[10:52:12] ~  ➜ gem uninstall rubocop
Remove executables:
        rubocop

in addition to the gem? [Yn]

patbl avatar Jun 03 '20 17:06 patbl

OK, it looks like my problem was caused by installing the Homebrew version of Tmuxinator, which installs a full version of Ruby with it:

[10:57:30] ~/.rbenv/versions  ➜ gem info rubocop

*** LOCAL GEMS ***

rubocop (0.82.0)
    Authors: Bozhidar Batsov, Jonas Arvidsson, Yuji Nakayama
    Homepage: https://github.com/rubocop-hq/rubocop
    License: MIT
    Installed at: /usr/local/Cellar/tmuxinator/2.0.1/libexec

    Automatic Ruby code style checking tool.

So I think there was some confusion between the Homebrew and Rbenv versions of Ruby 2.7.1. Uninstalling Tmuxinator and Ruby (brew uninstall tmuxinator ruby) wasn't enough to fix itβ€”if I reinstalled 2.7.1 using Rbenv, it would still show up in brew list. So I uninstalled Homebrew entirely and am now reinstalling everything. If that doesn't work I'll update this.

patbl avatar Jun 03 '20 18:06 patbl

Based on your output, it looks like a PATH issue finding the shim (zsh: command not found: rubocop), which is not the same as the shim running but unable to find the gem executable: rbenv: rubocop: command not found

longspell avatar Jun 03 '20 18:06 longspell

@mislav looks like rbenv REHASH does not take RubyGem's installation directory into account.

Rehash should be done on the gem env home directory rather than simply `.rbenv/versions/*/bin/

fzakaria avatar Jul 11 '20 18:07 fzakaria

I think when rehash is executed; the script should also also execute gem env home for each ruby installation and include those as well.

Should this be a separate issue as a feature request ?

As for the rationale why I am using user installation directory. I am using https://nixos.org/nixpkgs/manual/ to manage my ruby installation and symlinking it within ~/.rbenv/versions (rather than relying on ruby-build)

This works great; except the way Nix works is that it defaults the gem home to the user installation directory.

fzakaria avatar Jul 11 '20 18:07 fzakaria

Btw I have put up a nixpkg derivation for rbenv: https://github.com/NixOS/nixpkgs/pull/89433

fzakaria avatar Jul 11 '20 20:07 fzakaria

I have explored adding support for gem install --user-install to rbenv but ultimately decided that due to how rbenv works, adding support for this is unfeasible. https://github.com/rbenv/rbenv/pull/1443

The support for GEM_HOME still stays in rbenv edge and will be part of the next release.

mislav avatar Oct 07 '22 11:10 mislav

Anyone seeing this thread, you might want to take a look at my solution where I moved and made the user dir synonymous to the default dir in ~/.rbenv: https://github.com/rbenv/rbenv/pull/1436#issuecomment-1264238738

konsolebox avatar Oct 07 '22 11:10 konsolebox