title: How to fix 'Bundler could not install a gem because it needs to create a directory, but a file exists'
body: <p><code>bundle update</code> is failing with the following message <code>Bundler could not install a gem because it needs to create a directory, but a file exists</code> </p>
  
  <p>This occurs after editing a line in the Gemfile so that a gem is fetched from Github.</p>
  
  <p>I have never seen this error before, and am struggling to understand how to resolve it or to find any useful information online. </p>
  
  <p>I've ensured that bundler, rubygems and other relevant parts of my system are up-to-date. </p>
  
  <p>The bundler source indicates that this error is raised if coping to the destination fails. Line 117 <a href="https://github.com/bundler/bundler/blob/master/lib/bundler/source/git/git_proxy.rb" rel="nofollow">https://github.com/bundler/bundler/blob/master/lib/bundler/source/git/git_proxy.rb</a></p>
  
  <p>So I have tried removing the offending gem from the Gemfile, running bundle update and cleaning the gemset to remove all previous traces before re-adding and re-installing the gem. </p>
  
  <p>The error is still raised when fetching from github, but disappears when using rubygems. </p>
  
  <p>How to resolve this?</p>