chruby
chruby copied to clipboard
Possible issue with chruby-exec in Ubuntu?
We're trying to provide support for the invoker gem on Linux with chruby, as requested here. A bit of background about invoker:
- It's a mashup of the features of Pow web server and Foreman task runner.
- The gem is installed without
sudowhich meanschrubywill place the executable under~/.gem/ruby/<version>/bin. - After installation, the next step is running
sudo invoker setup. This is straight forward in OSX sincesudo gem envandgem envare 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 of env, gem env and $PATH when using sudo chruby-exec ... and without it are listed in this gist. You can see that the output of echo $PATH under sudo -E chruby-exec and without it are the same. However, the PATH key in the output of env is different.
Solutions to make the invoker gem to work are these:
-
Install the gem using the command
gem install invoker --bindir $RUBY_ROOT/binand the n runsudo -E chruby-exec 2.1.2 -- invoker setup. or -
Install with
gem install invokerand run thesudo invoker setuppart 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 with sudo -E? Is this a design choice?
OS: Ubuntu 14.04
Ruby: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
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.