Search code examples
ruby-on-railsubuntusudochruby

How to use chruby with sudo and foreman?


I am trying to use sudo with chruby and foreman, but without success.

I tried

$ sudo chruby-exec ruby-2.1.2 -- foreman
$ foreman: command not found

But the same command with rake command works fine.

$ sudo chruby-exec ruby-2.1.2 -- rake --version
$ rake, version 10.1.0

OS: Ubuntu 14.04

I haven't any ruby installed at root or at system, only at user.


Solution

  • I just ran $ sudo chruby-exec ruby-2.1.2 -- gem install foreman (as user) to install the gem inside chruby root user path and it is working now.

    To install the ruby to root:

    sudo ruby-install ruby 2.1.2
    

    To install the gem inside chruby root path:

    sudo chruby-exec ruby-2.1.2 -- gem install foreman
    

    To use foreman like a root:

    sudo chruby-exec ruby-2.1.2 -- foreman
    

    From docs:

    Correctly sets $GEM_HOME and $GEM_PATH.
    Users: gems are installed into ~/.gem/$ruby/$version.
    Root: gems are installed directly into /path/to/$ruby/$gemdir.