Using rbenv doesn't work with sudo?

后端 未结 4 1476
眼角桃花
眼角桃花 2020-12-10 07:56

Any commands that use sudo don\'t seem to work with RBenv.

I\'m trying to install ActiveRecord and it says I don\'t have write permission, so when I try

相关标签:
4条回答
  • 2020-12-10 08:00

    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.

    0 讨论(0)
  • 2020-12-10 08:11

    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

    0 讨论(0)
  • 2020-12-10 08:13

    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.

    0 讨论(0)
  • 2020-12-10 08:17

    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.

    0 讨论(0)
提交回复
热议问题