ruby 由于权限被拒绝,“捆绑安装”失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17959435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:06:08  来源:igfitidea点击:

`bundle install` failed due to permission denied

rubybundlerpermission-denied

提问by JoJoS

I've installed bundler gem on my new server and when I try to execute bundle install, it failed with this error :

我已经在我的新服务器上安装了 bundler gem,当我尝试执行时bundle install,它失败并出现以下错误:

Unfortunately, a fatal error has occurred. Please see the Bundler troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
/usr/lib/ruby/1.9.1/fileutils.rb:247:in `mkdir': Permission denied - /var/lib/gems (Errno::EACCES)

My server is a Debian wheezy (7.1) with default ruby 1.9.3 package installed. I have configured /etc/gemrc?like this : gem: --user-installto allow users install gems locally.

我的服务器是 Debian wheezy (7.1),安装了默认的 ruby​​ 1.9.3 软件包。我已经配置了/etc/gemrc?像这样:gem: --user-install允许用户在本地安装 gems。

The bundler gem was installed inside my user's gems dir ~/.gemlike i want with this command : gem install bundler(no sudo). But bundler want install gems into /var/lib/gemsinstead my gems directory :(

bundler gem 安装在我用户的 gems 目录中,~/.gem就像我想要的一样:(gem install bundler没有 sudo)。但是捆绑程序想要将 gems 安装到/var/lib/gems我的 gems 目录中:(

I don't understand what's wrong with bundler... Why it doesn't try to install gem where I want (in my gems local dir) ?

我不明白 bundler 有什么问题......为什么它不尝试在我想要的地方安装 gem(在我的 gems 本地目录中)?

ps: in my laptop, with archlinux and default ruby 2.0.0 package installed, I have no problems with bundler to install user's gems.

ps:在我的笔记本电脑中,安装了 archlinux 和默认的 ruby​​ 2.0.0 包,我用 bundler 安装用户的 gems 没有问题。

回答by JoJoS

I found !

我发现 !

I had updated my rubygem like this gem update --system. But only my local gems were update due to the gem: --user-installrestriction in my /etc/.gemrc. When bundler works, it use the global rubygem and not mine.

我已经像这样更新了我的 ruby​​gem gem update --system。但由于gem: --user-install我的/etc/.gemrc. 当 bundler 工作时,它使用全局 ruby​​gem 而不是我的。

To fixe this issue, I updated the global rubygems with : sudo gem update --system --no-user-install.

为了解决这个问题,我用 : 更新了全局 ruby​​gems sudo gem update --system --no-user-install

And all works fine !

一切正常!

回答by Oncle Tom

According to bundler documentation, a $BUNDLE_PATHor $GEM_HOMEenv variable can be set to make it the default writeable place.

根据bundler 文档,可以设置a$BUNDLE_PATH$GEM_HOMEenv 变量以使其成为默认的可写位置。

export BUNDLE_PATH=~/.gems

bundle install

It is pretty handy if you {do not have/do not want to use} root access.

如果您{没有/不想使用}根访问权限,这非常方便。

回答by Legion

bundle installdoes not use the gemrc settings. (Although possibly that has changedin a recent update, but the update appears to load ~/.gemrc only, not /etc/gemrc)

bundle install不使用 gemrc 设置。(虽然可能在最近的更新中发生了变化,但更新似乎只加载 ~/.gemrc,而不是 /etc/gemrc)

You can do what you want with bundle install --path ~/.gem

你可以随心所欲 bundle install --path ~/.gem

However, I would highly recommend getting rbenv or RVM working. You said that you had the "same result" with rbenv. If your gems were trying to install into /var/lib/gemswhen you had rbenv installed, then it wasn't an rbenv-installed Ruby that was running that command. Either rbenv was still using the system Ruby (which it will until you pick an rbenv installed Ruby to become the default), or you did not have rbenv running correctly.

但是,我强烈建议让 rbenv 或 RVM 工作。你说你用 rbenv 得到了“相同的结果”。如果您在安装/var/lib/gemsrbenv 时尝试安装 gems ,那么运行该命令的不是安装了 rbenv 的 Ruby。rbenv 仍在使用系统 Ruby(直到您选择安装了 rbenv 的 Ruby 成为默认系统),或者您没有正确运行 rbenv。