【问题标题】:cannot recover from `sudo bundle install`无法从“sudo bundle install”中恢复
【发布时间】:2014-09-27 19:42:43
【问题描述】:

我错误地在我的项目上运行了sudo bundle install,现在当我以自己的身份运行它bundle install 时,我收到了权限被拒绝错误(如下)。我在这里尝试了https://github.com/bundler/bundler/blob/master/ISSUES.md#other-problems 的说明,还尝试将我的项目克隆到一个新目录并从那里运行包,没有用。请帮忙!

error: cannot open .git/FETCH_HEAD: Permission denied

Retrying git fetch --force --quiet --tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b" due to error (2/3): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b"` in directory /usr/local/lib/ruby/gems/2.1.0/bundler/gems/em-postgresql-adapter-3dfcc60378e9 has failed.
If this error persists you could try removing the cache directory '/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b'
error: cannot open .git/FETCH_HEAD: Permission denied

Retrying git fetch --force --quiet --tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b" due to error (3/3): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b"` in directory /usr/local/lib/ruby/gems/2.1.0/bundler/gems/em-postgresql-adapter-3dfcc60378e9 has failed.
If this error persists you could try removing the cache directory '/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b'
error: cannot open .git/FETCH_HEAD: Permission denied

Git error: command `git fetch --force --quiet
--tags "/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b"` in directory
/usr/local/lib/ruby/gems/2.1.0/bundler/gems/em-postgresql-adapter-3dfcc60378e9
has failed.
If this error persists you could try removing the cache directory
'/home/akonsu/.bundler/cache/git/em-postgresql-adapter-361cdc05eba5661bb17040a7a6c2a093f9c2263b'

【问题讨论】:

标签: ruby bundler


【解决方案1】:

我今天在我的 mac 上遇到了同样的问题。我通过删除文件夹 ~/.bundle 解决了它。

之后,我运行bundle install --path ~/.bundle,一切都恢复正常了。

【讨论】:

  • 这应该是第一个答案!谢谢!
【解决方案2】:

将 repo 克隆到新目录将无济于事。您将 gems 安装到标准 gems 目录而不是特定于捆绑包的目录。

最好的选择是将捆绑包安装到新目录并忽略安装在系统路径中的 gem。

试试bundle install --path /home/akonsu/.new_project_bundle。您不必每次都指定此选项。它被记住了。

http://bundler.io/v1.3/man/bundle-install.1.html

您还需要设置打包器缓存目录的权限,如 cmets 中所述(或删除它)。

【讨论】:

  • 如果你想使用现有的已安装gems:在系统gem目录上设置正确的权限,这意味着授予普通用户对/usr/local/lib/ruby/gems/2.1的写入权限。 0。但这并不是一个好主意。另一个更简单的选择是将 GEM_HOME 设置为 ~/.ruby_gems/ 在您的 bashrc 或 bash_profile (或等效项)中。这再次意味着忽略您当前的安装。这也会影响其他 ruby​​ 应用程序,如果你有的话,因为他们不会在这个新的 GEM_HOME 中找到他们的宝石。您必须为所有应用程序进行捆绑安装。
【解决方案3】:

阅读捆绑商网站上提供的内容,无需外部帮助。

Gems 将安装到您的默认系统位置以供 gems 使用。如果您的系统 gem 存储在 root 拥有的位置(例如在 Mac OSX 中),bundle 将要求您输入 root 密码才能将它们安装在那里。

在安装 gem 时,Bundler 将检查供应商/缓存,然后检查系统的 gem。如果 gem 没有被缓存或安装,Bundler 将尝试从您在 Gemfile 中声明的源安装它。

--system 选项是默认选项。在使用--path 选项后将其传递给切换回来,如下所述。

将您的依赖项,甚至是已安装到系统 gem 中的 gem,安装到系统 gem 存储库以外的位置。在这种情况下,请将它们安装到供应商/捆绑包。

$ bundle install --path vendor/bundle

其他捆绑命令或对 Bundler.setup 或 Bundler.require 的调用将记住此位置。

来源:http://bundler.io/v1.9/bundle_install.html

【讨论】:

    【解决方案4】:

    我今天遇到了同样的问题。我从 /Library/Ruby/Gems/2.3.0/ 中删除了 bundler 目录,然后使用 sudo gem install bundler 重新安装了 bundler。相当激进的解决方案,但解决了问题。

    【讨论】:

      【解决方案5】:

      chmod 777 /usr/local/lib/ruby/gems/2.3.0/bundler/gems

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-14
        • 2017-04-13
        • 2021-11-04
        • 2016-08-02
        相关资源
        最近更新 更多