How to change bower's default cache folder?

ab.su.rd picture ab.su.rd · Jul 26, 2013 · Viewed 7.2k times · Source

On *nix, bower uses the ~/.bower folder for its cache (packages and so on).
I would like to change this to a different location.

The bower spec document from suggests that I configure the storage key in my .bowerrc.

I have created one in my project folder like so:

{
  "storage": {
     "cache": "~/blah/cached",
     "git": "~/blah/git_templates"
  }
}

When running bower install - i see that it still tries to save into ~/.bower.

Can anyone tell me what I am doing wrong here ? And/or if there is a different way to change the location ?

Answer

knightli picture knightli · Sep 2, 2013

I had the same problem, after some tries according the spec, I gave up...

So I reviewed bower's history on github and found:

  • Before v0.10.0, bower used config.cache (lib/core/ResolveCache.js) for its cache location
  • After that, satazor rewrote bower's core, now using config.storage.cache at the beginning, i bet the spec doc was written at this time. From the spec:

storage [object]

Where to store persistent data, such as cache, needed by bower. Defaults to paths that > suite the OS/platform. Valid keys are cache, registry, links, completion.

  • However, after this commit, satazor now uses config.storage.packages instead of config.storage.cache

  • After that, in the v1.0.0 release, the config is always set to config.storage.packages, but the spec has not reflected this change ever since

Solution

  • Export the environment variable bower_storage__packages
  • Use a .bowerrc such as:

    {
      "storage":{
          "packages":"/path/to/cache"
      }
    }
    

P.S.: I think that linking the spec doc in Google Docs isn't a good idea, maybe github would be a more sensible choice (since we can issue pull requests).