rbenv-communal-gems icon indicating copy to clipboard operation
rbenv-communal-gems copied to clipboard

Bins are not found after installing another version

Open joallard opened this issue 11 years ago • 13 comments

I had installed 1.9.3-p374 and communized all versions. Then, after a while, I installed 1.9.3-p448. RCG said it had done its stuff. Okay.

RBEnv stopped finding the bins. I looked at the other issues (#3, #4), but I'm not sure this is exactly the same thing.

  • rbenv rehash doesn't change anything
  • --env-shebang is there

Here's a bit of debugging around.


jon@panhandle:~/dev-cr/double-serum$ html2haml
rbenv: html2haml: command not found

The `html2haml' command exists in these Ruby versions:
  1.9.3-p374

jon@panhandle:~/dev-cr/double-serum$ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
jon@panhandle:~/dev-cr/double-serum$ ls ~/.rbenv/gems/1.9.1/gems/ | grep html
jon@panhandle:~/dev-cr/double-serum$ rbenv shell 1.9.3-p
1.9.3-p374  1.9.3-p448  
jon@panhandle:~/dev-cr/double-serum$ rbenv shell 1.9.3-p374 
jon@panhandle:~/dev-cr/double-serum$ html2haml
<html></html>
%html
jon@panhandle:~/dev-cr/double-serum$ rbenv which html2haml
/home/jon/.rbenv/versions/1.9.3-p374/bin/html2haml
jon@panhandle:~/dev-cr/double-serum$ rbenv which bundle # bundle worked oob
/home/jon/.rbenv/versions/1.9.3-p374/bin/bundle
jon@panhandle:~/dev-cr/double-serum$ rbenv shell 1.9.3-p448 
jon@panhandle:~/dev-cr/double-serum$ rbenv rehash 
jon@panhandle:~/dev-cr/double-serum$ html2haml
rbenv: html2haml: command not found

The `html2haml' command exists in these Ruby versions:
  1.9.3-p374

jon@panhandle:~/dev-cr/double-serum$ cat ~/.gemrc
cat: /home/jon/.gemrc: No such file or directory
jon@panhandle:~/dev-cr/double-serum$ cat ~/.rbenv/versions/1.9.3-p448/etc/gemrc
# added by rbenv communize
install: "--env-shebang"
gemhome: "/home/jon/.rbenv/gems/1.9.1"
jon@panhandle:~/dev-cr/double-serum$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2013-06-27 patchlevel 448) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/jon/.rbenv/gems/1.9.1
  - RUBY EXECUTABLE: /home/jon/.rbenv/versions/1.9.3-p448/bin/ruby
  - EXECUTABLE DIRECTORY: /home/jon/.rbenv/gems/1.9.1/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/jon/.rbenv/gems/1.9.1
     - /home/jon/.gem/ruby/1.9.1
     - /home/jon/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--env-shebang"
     - "gemhome" => "/home/jon/.rbenv/gems/1.9.1"
  - REMOTE SOURCES:
     - http://rubygems.org/
jon@panhandle:~/dev-cr/double-serum$ ls ~/.rbenv/gems/1.9.1/bin/
bundle  camping  forward  ghi  guard  pry  rails  sprockets  yard  yardoc  yri
jon@panhandle:~/dev-cr/double-serum$ cat ~/.rbenv/plugins/rbenv-communal-gems/.git/refs/heads/master 
cbc18bc791b3a25a6b1df27e256d02b9695bb537
jon@panhandle:~/dev-cr/double-serum$ rbenv communize --all
Gems for 1.9.2-p290 are already communal
Gems for 1.9.3-p374 are already communal
Gems for 1.9.3-p448 are already communal
Gems for 2.0.0-p247 are already communal

joallard avatar Aug 30 '13 19:08 joallard

Another common error:

jon@panhandle:~/dev-cr/abcdef$ rspec
/home/jon/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find rspec-core (>= 0) amongst [actionmailer-4.0.0, actionmailer-3.2.14, actionmailer-3.2.13, actionpack-4.0.0, actionpack-3.2.14, actionpack-3.2.13, activeadmin-0.6.0, activemodel-4.0.0, activemodel-3.2.14, activemodel-3.2.13, activerecord-4.0.0, activerecord-3.2.14, activerecord-3.2.13, ... blah blah blah no rspec] (Gem::LoadError)
    from /home/jon/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
    from /home/jon/.rbenv/versions/1.9.3-p374/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
    from /home/jon/.rbenv/versions/1.9.3-p374/bin/rspec:22:in `<main>'

joallard avatar Aug 30 '13 23:08 joallard

I think the problem here is that rbenv-communal-gems handles sharing the gems/ directory between ruby versions, but doesn't handle bin/ dirs.

For instance:

# Install a gem
  $ rbenv shell 2.1.0-preview1
  $ gem install haml
  # Result: you get ~/.rbenv/versions/2.1.0-preview1/bin/haml

# Check the gem in another version
  $ rbenv shell 2.1.0
  $ ruby -rhaml -e "puts 'haml loaded ok'" # okay
  $ haml
  # command not found: haml
  # ~/.rbenv/versions/2.1.0/bin/haml does *not* exist

rstacruz avatar Jan 07 '14 07:01 rstacruz

I've been using this script as a temporary fix. @tpope, any feedback on this issue? :)

rstacruz avatar Jan 07 '14 07:01 rstacruz

@rstacruz Thanks, your script works great! Had the same problem, installed a new Ruby version and all bins stopped working. Reinstalling the gems works, or running your script. @tpope Any plans to address this problem?

manuelmeurer avatar Mar 03 '14 11:03 manuelmeurer

I only recently managed to reproduce this myself, and haven't had time to dig in. Something like that script in an after install hook sounds promising. Though implementing it in Ruby is just begging for trouble.

tpope avatar Mar 03 '14 18:03 tpope

Completely agree that it shouldn't be implemented in Ruby :)

rstacruz avatar Mar 05 '14 05:03 rstacruz

Can a symlink be created from .rbenv/versions/1.9.3-p194/bin to .rbenv/gems/1.9./bin ?

eloyesp avatar Jun 30 '14 15:06 eloyesp

The symlink solution seems to work, but I used copy instead.

cp ~/.rbenv/versions/2.1.1/bin/rspec ~/.rbenv/gems/2.1.0/bin

eloyesp avatar Dec 16 '14 13:12 eloyesp

A pure symlink won't work because in addition to the gem executables there are also things like ruby, which cannot be shared.

Any chance we could get something like @rstacruz's gist merged?

ab avatar Nov 12 '15 23:11 ab

Could someone port it to bash?

tpope avatar Nov 12 '15 23:11 tpope

I took a stab at it, though it's a bit of a mess: https://gist.github.com/ab/b34fd3dfc7e185cd6e4c

I wasn't sure what to do with files in bin/ that have a shebang like #! $HOME/.rbenv/versions/2.1.6/bin/ruby, but copying them didn't seem like a good idea. There are also a handful of files that have a $!/bin/sh, which was a surprise.

ab avatar Nov 13 '15 05:11 ab

Isn't that doing a lot more than the aforementioned gist? Not saying it's wrong, but if it's right then this problem is even more complicated than I realized.

tpope avatar Nov 13 '15 05:11 tpope

Had to reinstall ruby 2.3.0 due to Sierra update. rbenv rehash does nothing to restore the bin stubs. Anything I can do to provide debug infos?

spiderpug avatar Dec 05 '16 13:12 spiderpug