Using rbenv doesn't work with sudo?

牧云@^-^@ 提交于 2019-11-29 07:06:21

The idea behind tools like rbenv and RVM is that you don't need to use sudo, because your entire Ruby environment exists inside your own workspace as a sandbox.

RVM allows multi-user configurations though it was originally designed for single users.

As far as I've ever seen or read, rbenv is single-user only. At no time should you need to use sudo to manipulate or change your Ruby environment when using rbenv. If you do, something is wrong. If you try to use sudo, you'll screw things up. You might not find out immediately but eventually something will pop up and you'll need to change the ownership of the files back to you.

On Linux and Mac OS you can do that pretty easily using:

sudo chown -R <your_user_name>:<your_group> ~/.rbenv

You have to run that as sudo because only the super-user can change ownership of files owned by root. sudo escalates your privileges to allow you to change those things.

I realise this is kind of old now, but this may help people in future:

rbenv-sudo is a plugin for rbenv that allows you to run rbenv-provided Rubies and Gems from within a sudo session.

https://github.com/dcarley/rbenv-sudo

James Lim

My answer in "Installing Ruby 2.0 and Rails 4.0.0beta on AWS EC2" might be useful to you.

In short, the root user needs to have rbenv loaded in its environment for you to use the gems installed by rbenv. This can be done by adding the following

# /etc/profile.d/rbenv.sh
export RBENV_ROOT=/usr/local/rbenv
export PATH="${RBENV_ROOT}/bin:$PATH"
eval "$(rbenv init -)"

This should be sufficient for sudo to work. If you are writing a shell script, you might need to use

. /etc/profile.d/rbenv.sh 

before using executables from other gems.

My answer is a little bit late but I have simple solution for this issue. Use symbolic links to be able use binstubs and other Ruby stuff.

ln -s ~/.rbenv/bin/rbenv /usr/local/bin/rbenv
ln -s ~/.rbenv/shims/* /usr/local/bin

I hope that helps to other users who is having the same issue.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!