2

I installed ruby using rbenv but after several attempts I don't manage to make the root user see the ruby bin.

I installed rbenv under /var/opt/rbenv

This is the content of /etc/profile.d/rbenv.sh:

export RBENV_ROOT=/var/opt/rbenv
export PATH=$RBENV_ROOT/bin:$PATH
eval "$(rbenv init -)"

As user pi, ruby -v returns ruby 2.2.2p95
But sudo ruby -v or ruby -v as root returns ruby not found.
How can I make root use my rbenv installation?
Should I fallback or RVM instead of rbenv?

Info: I need to run my ruby scripts as root in order to access the GPIOs.
Note: I need ruby >=2 so apt-get install ruby-full is not a solution.

closed as off-topic by Ghanima, goldilocks Apr 19 '15 at 15:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Ghanima, goldilocks
If this question can be reworded to fit the rules in the help center, please edit the question.

  • not found sounds like the path is not set correctly. Did you su or su -? Only the latter starts a new shell and therefore sources the scripts in /etc/profile.d. Try echo $PATH to check as root whether the setting of your profile.d are imported or not. – Ghanima Apr 19 '15 at 13:59
  • You are right, it works from sudo -i. I am trying to have it available in rc.local as well (as it is how my script will start) but no luck so far. How can I enrich the path in rc.local? – Balzard Apr 19 '15 at 14:42
  • sudo is configured to restrict how $PATH is set by default, but you can disable that. See here. – goldilocks Apr 19 '15 at 15:24
1

If you are calling your script from rc.local then call . /etc/profile.d/rbenv.sh before your script in rc.local . You can use source instead of . . ~/.bashrc and ~/.profile can be used for per user login settings. printenv is a good tool to check what is set.

Not the answer you're looking for? Browse other questions tagged or ask your own question.