postmodern / chruby

Changes the current Ruby
MIT License
2.85k stars 190 forks source link

Question: Does chruby support to run global commands (installed by root)? #361

Closed phongnh closed 8 years ago

phongnh commented 8 years ago

My use case: I usually install some useful gems with root user - for example: tmuxinator or rubocop so that I can use them for every project (with different Ruby versions) on Mac OS X. This setup works well with rbenv. Recently I switched from rbenv to chruby, however this setup works only if I use chruby system.

14:36:51 myproject (413cd1b:master) $ which tmuxinator
/usr/local/bin/tmuxinator
14:36:58 myproject (413cd1b:master) $ chruby
 * ruby-1.8.7-p375
   ruby-1.9.3-p551
   ruby-2.0.0-p648
   ruby-2.1.2
   ruby-2.3.0
14:37:03 myproject (413cd1b:master) $ tmuxinator version
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:296:in `to_specs': Could not find 'tmuxinator' (>= 0) among 37 total gem(s) (Gem::LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/dependency.rb:307:in `to_spec'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_gem.rb:47:in `gem'
    from /usr/local/bin/tmuxinator:22:in `<main>'
14:37:22 myproject (413cd1b:master) ! chruby system
14:37:26 myproject (413cd1b:master) $ tmuxinator version
tmuxinator 0.7.1
14:37:30 myproject (413cd1b:master) $ cat /usr/local/bin/tmuxinator
#!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'tmuxinator' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/
    version = $1
    ARGV.shift
  end
end

gem 'tmuxinator', version
load Gem.bin_path('tmuxinator', 'tmuxinator', version)

Is there any way to run those gems without installing them to all ruby versions?

Thanks.

postmodern commented 8 years ago

Not really. chruby sets separate GEM_HOME/GEM_PATH per ruby. Also rubygems has this annoying behavior of generating an explicit #!/path/to/ruby for all gem bin files.

phongnh commented 8 years ago

Thank you @postmodern.