Bundler不能在没有sudo的情况下安装任何宝石。

时间:2021-05-14 20:41:37

I'm trying to install a rails app and every time I use bundle it fails without sudo. My current situation is that everything works as long as use sudo for everything, including rails. I don't think this is correct.

我正在尝试安装一个rails应用程序,每次我使用bundle时,它都会在没有sudo的情况下失败。我目前的情况是,只要对所有东西(包括rails)使用sudo,一切都可以工作。我不认为这是正确的。

For example:

例如:

$ bundle update
Updating git://github.com/refinery/refinerycms.git
Fetching gem metadata from https://rubygems.org/.......
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Enter your password to install the bundled RubyGems to your system: 
Using rake (10.0.4) 
Using i18n (0.6.1) 
Using multi_json (1.7.2) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Installing hike (1.2.2) 
Errno::EACCES: Permission denied - /usr/local/rvm/gems/ruby-1.9.3-p194/build_info/hike-1.2.2.info
An error occurred while installing hike (1.2.2), and Bundler cannot continue.
Make sure that `gem install hike -v '1.2.2'` succeeds before bundling.

But then I do what it says and it works:

但后来我照它说的做了,它成功了:

$ gem install hike -v '1.2.2' 
Successfully installed hike-1.2.2
Parsing documentation for hike-1.2.2
Installing ri documentation for hike-1.2.2
Done installing documentation for hike after 0 seconds
1 gem installed

This pattern repeats again and again for different gems. I don't get it. Why is this happening? If I use sudo bundle will update without this error. But the current situation is that I need sudo for everything, including rake... or rails server, etc. Something isn't right.

这个模式在不同的宝石上反复出现。我不明白。为什么会这样?如果我使用sudo bundle,就不会出现这个错误。但目前的情况是,我什么都需要sudo,包括rake……或者rails服务器等等。

Additional details: I'm on OSX 10.8.3...

附加细节:我在OSX 10.8.3上……

$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
$ gem -v
2.0.3
$ rvm -v
rvm 1.19.6 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

$ which ruby
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby
$ which gem
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/gem
$ which rvm
/usr/local/rvm/bin/rvm

Update

更新

It may be informative that I can run sudo bundle install with no errors. Then immediately after bundle install fails with an error like you see above. Why is this?

我可以在没有错误的情况下运行sudo bundle install,这可能会提供一些有用的信息。然后在bundle install之后立即失败,出现了上面看到的错误。这是为什么呢?

Update2

更新2

/usr/local/rvm[master]$ ls -l
total 56
-rw-rw-r--   1 root  rvm   566 May  4 12:59 LICENCE
-rw-rw-r--   1 root  rvm  8929 May  4 12:59 README
-rw-rw-r--   1 root  rvm     7 May  4 12:59 RELEASE
-rw-rw-r--   1 root  rvm     7 May  4 12:59 VERSION
drwxrwsr-x   3 root  rvm   102 May  4 01:34 archives
drwxrwsr-x  35 root  rvm  1190 May  4 12:59 bin
drwxrwsr-x  11 root  rvm   374 May  4 12:59 config
drwxrwsr-x   6 root  rvm   204 Jan 10 19:55 contrib
drwxrwsr-x   5 root  rvm   170 Jan 10 19:55 environments
drwxrwsr-x   3 root  rvm   102 Jan 10 19:55 examples
drwxrwsr-x   5 root  rvm   170 Jan 10 19:52 gems
drwxrwxr-x   6 ESL   rvm   204 May  4 12:59 gemsets
drwxrwsr-x  92 root  rvm  3128 May  4 01:34 help
drwxrwsr-x  11 root  rvm   374 May  4 01:34 hooks
-rw-rw-r--   1 root  rvm    11 May  4 12:59 installed.at
drwxrwsr-x   4 root  rvm   136 Jan 10 19:54 lib
drwxrwsr-x   5 root  rvm   170 May  4 12:55 log
drwxrwsr-x   2 root  rvm    68 Jan 10 19:52 man
drwxrwsr-x   9 root  rvm   306 Jan 10 19:52 patches
drwxrwxr-x   4 ESL   rvm   136 May  4 12:59 patchsets
drwxrwsr-x   4 root  rvm   136 Jan 10 19:55 rubies
drwxrwsr-x  64 root  rvm  2176 May  4 01:34 scripts
drwxrwsr-x   3 root  rvm   102 May  4 01:34 src
drwxrwsr-x   2 root  rvm    68 Jan 10 19:52 tmp
drwxrwsr-x   8 root  rvm   272 May  4 12:59 user
drwxrwsr-x   4 root  rvm   136 Jan 10 19:52 usr
drwxrwsr-x   5 root  rvm   170 Jan 10 19:55 wrappers

6 个解决方案

#1


41  

You may host gems in your user home folder, that does not need root permissions:

您可以在用户主文件夹中托管gems,不需要root权限:

bundle install --path ~/.gem

包安装~ / .gem——路径

To avoid passing this parameter manually add export GEM_HOME=$HOME/.gem to your .bash_profile -- this solves sudo issue on Mac OS and other *nix systems. You then also might need to have access to gems that provide executables (such as bundler), so add this too:

为了避免手动传递此参数,添加export GEM_HOME=$HOME/。gem到您的.bash_profile——这解决了Mac OS和其他*nix系统上的sudo问题。然后,您可能还需要访问提供可执行文件(如bundler)的gems,因此也添加以下内容:

PATH=$PATH:$HOME/.gem/bin

or in some cases:

或者在某些情况下:

PATH=$PATH:$HOME/.gem/ruby/<version>/bin

ref: https://*.com/a/5862327/322020

裁判:https://*.com/a/5862327/322020


UPD: But keep in mind that if you start using rbenv having this environment variable be the same might cause problems when using too different versions of Ruby, so you might want to temporary unset GEM_HOME or prepend custom one each time you launch rbenv-ed Ruby.

但是请记住,如果您开始使用rbenv时使用的环境变量相同,在使用不同版本的Ruby时可能会导致问题,所以您可能希望在每次启动rbenv-ed Ruby时临时取消GEM_HOME或prepend custom。

#2


16  

Your RVM gem directory should be owned by the rvm group. So, instead of changing ownership, it might be wise to simply add the user to the rvm group:

您的RVM gem目录应该由RVM组拥有。因此,与其改变所有权,不如将用户添加到rvm组:

# $(whoami) evaluates to your username
# You may want to change this to a different username depending on your config
# but $(whoami) is a passable default
usermod -a -G rvm $(whoami)

#3


7  

This is due to the way you installed ruby.

这是由于您安装ruby的方式。

Frankly, it works *just fine* if you don't mind the sudo. At the end of the day, it's just your laptop... Not some server running in a bank.

坦白地说,如果你不介意sudo的话,它可以正常工作。说到底,这只是你的笔记本电脑……不是运行在银行中的某个服务器。

If you really care, chown gem folders as needed.

如果你真的在乎的话,你可以根据需要选择chown gem文件夹。

#4


2  

I had this happen today. This might be a unique situation, but I had copied a Rails source tree from a system that had RVM installed globally (system-wide in /usr/local/rvm), to a system that just had RVM installed per-user (~/.rvm).

这是我今天做的。这可能是一种独特的情况,但是我将RVM安装在全局的系统(在/usr/local/rvm中)中的Rails源树复制到每个用户都安装了RVM的系统(~/. RVM)。

I was trying to do bundle install and getting the "Your user account isn't allowed to install to the system Rubygems." error. After a lot of poking around, I noticed that in my ~/.rvm directory there was a symbolic link:

我试图做捆绑安装,并得到“您的用户帐户不允许安装到系统Rubygems。”在我到处闲逛之后,我注意到在我的~中。rvm目录中有一个符号链接:

~/.rvm/gems/ruby-2.1.1/cache -> /usr/local/rvm/gems/cache

Removing that symlink got bundle install working again without sudo.

删除symlink使bundle安装再次工作而不需要sudo。

#5


1  

I had the same problem and found out that Bundler before installing new gems checks if it has write permission for all files found $GEM_HOME/build_info. In my case it didn't, because although user that run bundler was in 'rvm' user group and that group owned all those files, group wasn't allowed to write some of them.

我也遇到了同样的问题,在安装新的gems之前,我发现Bundler检查它是否对所有文件都有写权限,找到了$GEM_HOME/build_info。在我的例子中,它没有,因为尽管运行bundler的用户属于“rvm”用户组,该组拥有所有这些文件,但组不允许编写其中的一些文件。

That happened because I installed some of the gems under root, which has umask 0022 (all files created by root, can't be written by group) instead of umask 0002 that others have and which rvm expects.

这是因为我在root下安装了一些gems,它有umask 0022(所有由root创建的文件都不能由group编写),而不是其他人拥有的和rvm期望的umask 0002。

#6


0  

If you are using RVM, then do these two steps and you'll be golden

如果您使用RVM,那么执行这两个步骤,您就会变成黄金。

  1. Make sure your user belongs to the RVM group

    确保您的用户属于RVM组

    sudo usermod -a -G rvm myUserName

    sudo usermod -a -G rvm用户名

  2. Make sure build_info is writable for all users in the RVM group

    确保build_info对RVM组中的所有用户都是可写的

    sudo chmod 664 $GEM_HOME/build_info/*

    sudo chmod 664美元GEM_HOME / build_info / *

#1


41  

You may host gems in your user home folder, that does not need root permissions:

您可以在用户主文件夹中托管gems,不需要root权限:

bundle install --path ~/.gem

包安装~ / .gem——路径

To avoid passing this parameter manually add export GEM_HOME=$HOME/.gem to your .bash_profile -- this solves sudo issue on Mac OS and other *nix systems. You then also might need to have access to gems that provide executables (such as bundler), so add this too:

为了避免手动传递此参数,添加export GEM_HOME=$HOME/。gem到您的.bash_profile——这解决了Mac OS和其他*nix系统上的sudo问题。然后,您可能还需要访问提供可执行文件(如bundler)的gems,因此也添加以下内容:

PATH=$PATH:$HOME/.gem/bin

or in some cases:

或者在某些情况下:

PATH=$PATH:$HOME/.gem/ruby/<version>/bin

ref: https://*.com/a/5862327/322020

裁判:https://*.com/a/5862327/322020


UPD: But keep in mind that if you start using rbenv having this environment variable be the same might cause problems when using too different versions of Ruby, so you might want to temporary unset GEM_HOME or prepend custom one each time you launch rbenv-ed Ruby.

但是请记住,如果您开始使用rbenv时使用的环境变量相同,在使用不同版本的Ruby时可能会导致问题,所以您可能希望在每次启动rbenv-ed Ruby时临时取消GEM_HOME或prepend custom。

#2


16  

Your RVM gem directory should be owned by the rvm group. So, instead of changing ownership, it might be wise to simply add the user to the rvm group:

您的RVM gem目录应该由RVM组拥有。因此,与其改变所有权,不如将用户添加到rvm组:

# $(whoami) evaluates to your username
# You may want to change this to a different username depending on your config
# but $(whoami) is a passable default
usermod -a -G rvm $(whoami)

#3


7  

This is due to the way you installed ruby.

这是由于您安装ruby的方式。

Frankly, it works *just fine* if you don't mind the sudo. At the end of the day, it's just your laptop... Not some server running in a bank.

坦白地说,如果你不介意sudo的话,它可以正常工作。说到底,这只是你的笔记本电脑……不是运行在银行中的某个服务器。

If you really care, chown gem folders as needed.

如果你真的在乎的话,你可以根据需要选择chown gem文件夹。

#4


2  

I had this happen today. This might be a unique situation, but I had copied a Rails source tree from a system that had RVM installed globally (system-wide in /usr/local/rvm), to a system that just had RVM installed per-user (~/.rvm).

这是我今天做的。这可能是一种独特的情况,但是我将RVM安装在全局的系统(在/usr/local/rvm中)中的Rails源树复制到每个用户都安装了RVM的系统(~/. RVM)。

I was trying to do bundle install and getting the "Your user account isn't allowed to install to the system Rubygems." error. After a lot of poking around, I noticed that in my ~/.rvm directory there was a symbolic link:

我试图做捆绑安装,并得到“您的用户帐户不允许安装到系统Rubygems。”在我到处闲逛之后,我注意到在我的~中。rvm目录中有一个符号链接:

~/.rvm/gems/ruby-2.1.1/cache -> /usr/local/rvm/gems/cache

Removing that symlink got bundle install working again without sudo.

删除symlink使bundle安装再次工作而不需要sudo。

#5


1  

I had the same problem and found out that Bundler before installing new gems checks if it has write permission for all files found $GEM_HOME/build_info. In my case it didn't, because although user that run bundler was in 'rvm' user group and that group owned all those files, group wasn't allowed to write some of them.

我也遇到了同样的问题,在安装新的gems之前,我发现Bundler检查它是否对所有文件都有写权限,找到了$GEM_HOME/build_info。在我的例子中,它没有,因为尽管运行bundler的用户属于“rvm”用户组,该组拥有所有这些文件,但组不允许编写其中的一些文件。

That happened because I installed some of the gems under root, which has umask 0022 (all files created by root, can't be written by group) instead of umask 0002 that others have and which rvm expects.

这是因为我在root下安装了一些gems,它有umask 0022(所有由root创建的文件都不能由group编写),而不是其他人拥有的和rvm期望的umask 0002。

#6


0  

If you are using RVM, then do these two steps and you'll be golden

如果您使用RVM,那么执行这两个步骤,您就会变成黄金。

  1. Make sure your user belongs to the RVM group

    确保您的用户属于RVM组

    sudo usermod -a -G rvm myUserName

    sudo usermod -a -G rvm用户名

  2. Make sure build_info is writable for all users in the RVM group

    确保build_info对RVM组中的所有用户都是可写的

    sudo chmod 664 $GEM_HOME/build_info/*

    sudo chmod 664美元GEM_HOME / build_info / *