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

cannot find --user-installd gem executable #1232

Closed
longspell opened this issue Mar 26, 2020 · 15 comments · Fixed by #1436
Closed

cannot find --user-installd gem executable #1232

longspell opened this issue Mar 26, 2020 · 15 comments · Fixed by #1436

Comments

@longspell
Copy link

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.

@mislav
Copy link
Member

mislav commented Mar 26, 2020

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?

@longspell
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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```

@mislav
Copy link
Member

mislav commented Mar 26, 2020

@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 mislav closed this as completed Mar 26, 2020
@mislav
Copy link
Member

mislav commented Mar 26, 2020

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 mislav reopened this Mar 26, 2020
@mislav mislav changed the title rbenv cannot find gem executable cannot find --user-installd gem executable Mar 26, 2020
@longspell
Copy link
Author

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.

@patbl
Copy link

patbl commented Jun 3, 2020

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
Copy link

patbl commented Jun 3, 2020

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.

@longspell
Copy link
Author

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

@fzakaria
Copy link

@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
Copy link

fzakaria commented Jul 11, 2020

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
Copy link

Btw I have put up a nixpkg derivation for rbenv: NixOS/nixpkgs#89433

@mislav
Copy link
Member

mislav commented Oct 7, 2022

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. #1443

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

@mislav mislav closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2022
@konsolebox
Copy link

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: #1436 (comment)

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

Successfully merging a pull request may close this issue.

5 participants