Open kgrz opened 10 years ago
chruby will not add ~/.gem/...
to $GEM_PATH
when you are root. The idea being, if you are installing gems as root, you probably want to install them in the rubies own gemdir. Also, it's generally not a good idea to invoke user binaries with sudo.
Perhaps you could do something like chruby-exec 2.1.2 -- sudo -E ...
. Although, it appears sudo -E
is still clobbering $PATH
.
@postmodern The gem is not being installed as root btw. What we want is able to execute binary provided by gem via sudo
. it should ideally work as documented here - https://github.com/postmodern/chruby/wiki/Sudo
Are we considering binaries provided by stock ruby to be safer than those provided by gems? I don't see why binaries installed in RUBY_ROOT
works but not in gem root. The distinction seems arbitrary and entirely out of scope for something like chruby.
sudo -E
clobbers $PATH
and other environment variables depending on security policy of operating system btw. But if chruby
is at all meant to be used via sudo
the workarounds should work.
Note that I had the issue on OS X.
The gem installed fine, but when called using sudo without -E
the setup wouldn't run due to path errors.
We're trying to provide support for the
invoker
gem on Linux withchruby
, as requested here. A bit of background about invoker:sudo
which meanschruby
will place the executable under~/.gem/ruby/<version>/bin
.sudo invoker setup
. This is straight forward in OSX sincesudo gem env
andgem env
are same. However, on Linux, thesudo
-ed command should be run by the command listed in the issuesudo -E chruby-exec 2.1.2 -- invoker setup
.However, that command returns an error saying the executable
invoker
was not found. The outputs ofenv
,gem env
and$PATH
when usingsudo chruby-exec ...
and without it are listed in this gist. You can see that the output ofecho $PATH
undersudo -E chruby-exec
and without it are the same. However, thePATH
key in the output ofenv
is different.Solutions to make the
invoker
gem to work are these:gem install invoker --bindir $RUBY_ROOT/bin
and the n runsudo -E chruby-exec 2.1.2 -- invoker setup
. orInstall with
gem install invoker
and run thesudo invoker setup
part with this command:sudo -E chruby-exec 2.1.2 -- ~/.gem/ruby//bin/invoker setup
Which is pretty tasking.
My question is, why isn't
chruby-exec
not loading binaries under~/.gem/ruby/version/bin
when run withsudo -E
? Is this a design choice?