无法从`sudo bundle install`中恢复

时间:2014-09-27 19:42:44

标签: ruby bundler

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

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'

5 个答案:

答案 0 :(得分:27)

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

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

答案 1 :(得分:10)

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

最佳选择是将软件包安装到新目录并忽略系统路径中安装的gem。

试试bundle install --path /home/akonsu/.new_project_bundle。您不必每次都指定此选项。人们记得。

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

此外,您还需要设置捆绑器缓存目录的权限,如注释中所述(或删除它)。

答案 2 :(得分:2)

阅读Bundler网站上的内容,不需要任何外部帮助。

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

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

--system选项是默认选项。使用--path选项后,将其传递回切换。

将您的依赖项(甚至是已安装到系统gem中的gem)安装到系统的gem存储库以外的位置。在这种情况下,请将它们安装到vendor / bundle。

$ bundle install --path vendor/bundle

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

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

答案 3 :(得分:0)

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

答案 4 :(得分:-1)

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