Reputation: 1997
I am trying to use rbenv to manage ruby versions, but I am having issues keeping that version when switching users. I also concerned that my www-data user is not picking rbenv's ruby versions up, but I don't have any proof that it is doing this other than my inability to switch users.
Ruby 2.2.3 is set as the global ruby version as explained in the rbenv docs, this works for the user deploy. In my ~/.bashrc (for user deploy), i have the following code:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
When I login as deploy, everything works fine. However, when I su to root, my ruby version is broken. Here's what it looks like when I work on the command line:
> deploy@localhost:/var/www/my_app/current$ ruby -v ruby 2.2.3p173
> (2015-08-18 revision 51636) [x86_64-linux]
> deploy@localhost:/var/www/my_app/current$ su root Password:
> root@localhost:/var/www/my_app/current# ruby -v ruby 1.9.3p484
> (2013-11-22 revision 43786) [x86_64-linux]
> root@localhost:/var/www/my_app/current# su deploy
> deploy@localhost:/var/www/my_app/current$ ruby -v ruby 2.2.3p173
> (2015-08-18 revision 51636) [x86_64-linux]
I originally installed rbenv as root, but this broke because no other user accounts could access rbenv because of permission issue! After learning this, I installed it as deploy, and it works fine under that account, but not for any other accounts. Any other users can't even access rbenv...
Did I do something wrong?! Thanks for your help!
Upvotes: 0
Views: 230
Reputation: 43825
You're running into this issue because rbenv is designed to work on a per user basis, not as a "global" program. You've seen these symptoms:
www-data
gives root
odd issuesroot
gives www-data
access issuesMy preferred option would be to install rbenv individually for root
and www-dev
. I'd go that route since it limits the number of accounts that have access to rbenv/ruby, following best practices of limiting executables/liability on systems.
As an alternative, you can install rbenv so that all users have access to it. For that you can use /etc/profile.d
:
# From: https://gist.github.com/jnx/1256593#file-rbenv-install-system-wide-sh
# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# Add rbenv to the path:
echo '# rbenv setup' > /etc/profile.d/rbenv.sh
echo 'export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/rbenv.sh
echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
chmod +x /etc/profile.d/rbenv.sh
source /etc/profile.d/rbenv.sh
This ought to setup rbenv for any user that uses the system -- for better or worse.
Upvotes: 0