cannot recover from `sudo bundle install`

独自空忆成欢 提交于 2020-08-04 02:33:49

问题


by mistake I ran sudo bundle install on my project and now when I run it as myself bundle install I am getting permission denied errors (below). I tried the instructions here https://github.com/bundler/bundler/blob/master/ISSUES.md#other-problems, also tried cloning my project into a fresh directory and running bundle from there, no use. Please help!

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'

回答1:


Cloning the repo to a new directory would not help. You installed the gems to the standard gems directory instead of a bundle specific directory.

The best option is to install the bundle to a new directory and ignore the gems installed in the system path.

Try bundle install --path /home/akonsu/.new_project_bundle. You do not have to specify this option every time. It is remembered.

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

Also you need to set the permissions of the bundler's cache directory as mentioned in the comments (or delete it).




回答2:


I had today the same issue today in my mac. I solved it by deleting the folder ~/.bundle .

After that I run bundle install --path ~/.bundle and everything was working fine again.




回答3:


Read what's given on the bundler's website and no external help would be needed.

Gems will be installed to your default system location for gems. If your system gems are stored in a root-owned location (such as in Mac OSX), bundle will ask for your root password to install them there.

While installing gems, Bundler will check vendor/cache and then your system's gems. If a gem isn't cached or installed, Bundler will try to install it from the sources you have declared in your Gemfile.

The --system option is the default. Pass it to switch back after using the --path option as described below.

Install your dependencies, even gems that are already installed to your system gems, to a location other than your system's gem repository. In this case, install them to vendor/bundle.

$ bundle install --path vendor/bundle

Further bundle commands or calls to Bundler.setup or Bundler.require will remember this location.

Source: http://bundler.io/v1.9/bundle_install.html




回答4:


I had the same issue today. I deleted the bundler directory from /Library/Ruby/Gems/2.3.0/ and then reinstalled bundler with sudo gem install bundler. Quite radical solution but solves the issue.




回答5:


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



来源:https://stackoverflow.com/questions/26078493/cannot-recover-from-sudo-bundle-install

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!