Search code examples
rubyrubygemsbundler

Updating Gemfile.lock fails


I've updated a gem version in my Gemfile, so I'm trying to update Gemfile.lock. I run:

$ bundle update
Fetching gem metadata from https://rubygems.org/......
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies.......
Fetching rake 10.5.0
Fetching i18n 0.8.1
Fetching minitest 5.7.0
Fetching thread_safe 0.3.6
....

And get the following error despite it seems to be fetched already (see output above):

Bundler::GemspecError: Could not read gem at /usr/lib/ruby/gems/2.4.0/cache/rake-10.5.0.gem. It may be corrupted.
An error occurred while installing rake (10.5.0), and Bundler cannot continue.
Make sure that `gem install rake -v '10.5.0'` succeeds before bundling.

There's no such file under /usr/lib/ruby/gems/2.4.0/cache/. The cache directory is writable (777).

If I run gem install rake -v '10.5.0' it works fine. But do I really need to install gems manually (error repeats for other packages)? I don't get such errors if just run bundle install without updating gems.


Solution

  • Turned out that setting write permissions on cache directory (/usr/lib/ruby/gems/2.4.0/cache/) is not enough. You have to set write permissions for the parent directory (/usr/lib/ruby/gems/2.4.0/). For some reason, bundle update doesn't write to cache unless you do that even though it doesn't write anything to any other directories on the same level as cache.