13

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'
akonsu
  • 28,824
  • 33
  • 119
  • 194
  • `chown -R akonsu:akonsu /home/akonsu/.bundler` ? – Smar Sep 27 '14 at 19:49
  • Or removing the cache dir like the error said...? – Smar Sep 27 '14 at 19:50
  • tried that... I am the owner. – akonsu Sep 27 '14 at 19:52
  • Also there seems to be multiple other questions with same problem... http://stackoverflow.com/questions/16376995/bundler-cannot-install-any-gems-without-sudo?rq=1 http://stackoverflow.com/questions/17959435/bundle-install-failed-due-to-permission-denied?rq=1 – Smar Sep 27 '14 at 19:53
  • thanks. multiple other questions with the same symptoms rather. – akonsu Sep 27 '14 at 20:36

5 Answers5

34

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.

marcosfad
  • 341
  • 2
  • 3
10

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).

brahmana
  • 1,286
  • 12
  • 24
  • If you want to use the existing installed gems : Setting the right permissions on the system gem directory, which means giving the regular user write permissions to /usr/local/lib/ruby/gems/2.1.0. But that isn't really a good idea. Another simpler option would be to set GEM_HOME to something like ~/.ruby_gems/ in your bashrc or bash_profile (or equivalent). This again means ignore your current installation. Also this will affect other ruby apps, if you have any, as they would not find their gems in this new GEM_HOME. You will have to do bundle install for all the apps. – brahmana Sep 27 '14 at 20:45
1

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

Nakilon
  • 34,866
  • 14
  • 107
  • 142
0

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.

-1

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

Bluebaron
  • 2,289
  • 2
  • 27
  • 37