rubyubuntuchruby

chruby and ruby not available when I use sudo


I have installed chruby on ubuntu 14.04 and installed ruby-install and installed ruby 2.1.1 into /opt/rubies/

I have put the following into /etc/profile.d/chruby.sh

if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then
  source /usr/local/share/chruby/chruby.sh
  chruby ruby-2.1.2
fi

I want all users to use that ruby and there is no default ruby package installed.

If I do chruby logged in as myself I get:

ubuntuserver ~: chruby
 * ruby-2.1.2

And ruby -v gives:

ubuntuserver ~: ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [i686-linux]

However if I do sudo chruby I get:

sudo: chruby: command not found

And if I do something like sudo rmate myfile.txt I get:

ubuntuserver ~: sudo rmate test.txt

/usr/bin/env: ruby: No such file or directory

I want to know how to make that ruby universal to users sessions jobs webserver etc.


Solution

  • This question appears to have been answered on the chruby wiki

    In essence you would have to get a root prompt and then run the chruby setup script , switch rubies then run your command ..

    Alternatively you can use sudo chruby-exec ruby-n.n.n -- [command]

    eg. If I run

    sudo chruby-exec ruby-2.1.2 -- rmate test.txt
    

    it does invoke textmate as required.