使用rbenv不适用于sudo?

时间:2021-05-24 21:46:25

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

任何使用sudo的命令似乎都不适用于RBenv。

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

我正在尝试安装ActiveRecord,它说我没有写权限,所以当我尝试这个时:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions into the /usr/local/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1 directory.

It says:

sudo: gem: command not found

How can I get around this?

我怎么能绕过这个?

4 个解决方案

#1


11  

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.

像rbenv和RVM这样的工具背后的想法是你不需要使用sudo,因为你的整个Ruby环境都存在于你自己的工作区中作为沙箱。

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

RVM允许多用户配置,尽管它最初是为单个用户设计的。

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.

就我所见过或读过而言,rbenv仅为单用户。在使用rbenv时,您在任何时候都不需要使用sudo来操作或更改Ruby环境。如果你这样做,那就错了。如果你试图使用sudo,那你就搞砸了。您可能无法立即找到,但最终会弹出一些内容,您需要将文件的所有权更改回给您。

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

在Linux和Mac OS上,您可以使用以下方法轻松完成:

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.

您必须将其作为sudo运行,因为只有超级用户才能更改root拥有的文件的所有权。 sudo升级您的权限以允许您更改这些内容。

#2


2  

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.

rbenv-sudo是rbenv的插件,允许您在sudo会话中运行rbenv提供的Rubies和Gems。

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

#3


0  

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

我在“在AWS EC2上安装Ruby 2.0和Rails 4.0.0beta”的答案可能对您有用。

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

简而言之,root用户需要在其环境中加载rbenv才能使用rbenv安装的gem。这可以通过添加以下内容来完成

# /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

这应该足以让sudo工作。如果您正在编写shell脚本,则可能需要使用

. /etc/profile.d/rbenv.sh 

before using executables from other gems.

在使用其他宝石的可执行文件之前。

#4


-1  

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.

我的回答有点晚,但我对此问题有简单的解决方案。使用符号链接可以使用binstubs和其他Ruby东西。

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.

我希望这有助于遇到同样问题的其他用户。

#1


11  

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.

像rbenv和RVM这样的工具背后的想法是你不需要使用sudo,因为你的整个Ruby环境都存在于你自己的工作区中作为沙箱。

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

RVM允许多用户配置,尽管它最初是为单个用户设计的。

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.

就我所见过或读过而言,rbenv仅为单用户。在使用rbenv时,您在任何时候都不需要使用sudo来操作或更改Ruby环境。如果你这样做,那就错了。如果你试图使用sudo,那你就搞砸了。您可能无法立即找到,但最终会弹出一些内容,您需要将文件的所有权更改回给您。

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

在Linux和Mac OS上,您可以使用以下方法轻松完成:

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.

您必须将其作为sudo运行,因为只有超级用户才能更改root拥有的文件的所有权。 sudo升级您的权限以允许您更改这些内容。

#2


2  

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.

rbenv-sudo是rbenv的插件,允许您在sudo会话中运行rbenv提供的Rubies和Gems。

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

#3


0  

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

我在“在AWS EC2上安装Ruby 2.0和Rails 4.0.0beta”的答案可能对您有用。

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

简而言之,root用户需要在其环境中加载rbenv才能使用rbenv安装的gem。这可以通过添加以下内容来完成

# /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

这应该足以让sudo工作。如果您正在编写shell脚本,则可能需要使用

. /etc/profile.d/rbenv.sh 

before using executables from other gems.

在使用其他宝石的可执行文件之前。

#4


-1  

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.

我的回答有点晚,但我对此问题有简单的解决方案。使用符号链接可以使用binstubs和其他Ruby东西。

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.

我希望这有助于遇到同样问题的其他用户。