# Getting Cannot open: Permission denied when trying to restore cache

**URL:** <https://discuss.circleci.com/t/getting-cannot-open-permission-denied-when-trying-to-restore-cache/14063>\
**Category:** Build Environment\
**Tags:** nodejs\
**Created:** [July 7, 2017, 10:17pm UTC](https://discuss.circleci.com/t/getting-cannot-open-permission-denied-when-trying-to-restore-cache/14063 "2017-07-07T22:17:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danqa](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/danqa/32/15917_2.png) [@danqa](https://discuss.circleci.com/u/danqa)\
**Post date:** [July 7, 2017, 10:17pm UTC](https://discuss.circleci.com/t/getting-cannot-open-permission-denied-when-trying-to-restore-cache/14063/1 "2017-07-07T22:17:59Z")

</div>

I am trying to restore cache. I have a Node Container and when I install npm packages globally they are being put into /usr/local/bin (circle 2.0). In circle 1 they were in /opt/circleci/nodejs/v6.10.3/bin/

Now when I run a new job and try to restore the cache keys I get the following error:

Unarchiving cache…  
tar: usr/local/bin/\_mocha: Cannot open: Permission denied  
tar: usr/local/bin/aws: Cannot open: File exists  
tar: usr/local/bin/aws.cmd: Cannot open: Permission denied  
tar: usr/local/bin/aws\_bash\_completer: Cannot open: Permission denied

I assume this is because the circleci user doesn’t have privileges but if that is the case how do I restore the cache?

As a side note, I have been playing with circle 2.0 for a while now. Its WAY faster but the documentation is greatly lacking. Example of this stuff would be immensely helpful.

Sincerely

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [July 9, 2017, 3:09am UTC](https://discuss.circleci.com/t/getting-cannot-open-permission-denied-when-trying-to-restore-cache/14063/2 "2017-07-09T03:09:15Z")

</div>

Hi,

Can you provide snippets of your config file? Also, the NodeJS image that you are using.

---

<div class="post-metadata">

**Author:** ![danqa](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/danqa/32/15917_2.png) [@danqa](https://discuss.circleci.com/u/danqa)\
**Post date:** [July 10, 2017, 2:19pm UTC](https://discuss.circleci.com/t/getting-cannot-open-permission-denied-when-trying-to-restore-cache/14063/3 "2017-07-10T14:19:12Z")

</div>

```
version: 2

jobs:
  build:
    working_directory: ~/common-js
    resource_class: large
    docker:
      - image: circleci/node:6.10.3-browsers
    steps:
      - checkout
      - restore_cache:
          keys:
            # See if this exact revision was already built
            - dependency-cache-{{ .Branch }}-{{ .Revision }}
            # Else look for a previous build of this branch
            - dependency-cache-{{ .Branch }}
            # Else master
            - dependency-cache-master
      - run:
          name: install pip
          command: |
            sudo apt-get update
            sudo apt-get install -y python-dev python-pip
      - run:
          name: install aws cli (needed for deploys)
          command: sudo pip install awscli
      - run:
          name: setup npm dependencies
          command: |
            if [! -e /opt/circleci/nodejs/v6.10.3/bin/mocha]; then sudo npm i -g jasmine-node mocha; fi
            if [! -e /opt/circleci/nodejs/v6.10.3/bin/eslint]; then sudo npm i -g eslint@3.19.0; fi
            if [! -e /opt/circleci/nodejs/v6.10.3/lib/node_modules/eslint-plugin-mocha]; then sudo npm i -g eslint-plugin-mocha; fi
- save_cache:
      key: dependency-cache-{{ .Branch }}-{{ .Revision }}
      paths:
        - /usr/local/lib
        - /usr/local/lib/node_modules

```

In circle 1 they were in /opt/local/but now they are in usr/local/bin and that cache cannot be restored due to permissions issues as stated above. Let me know if you need anymore info. I am blocked at the moment as a result of this.

Sincerely,

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [July 10, 2017, 5:07pm UTC](https://discuss.circleci.com/t/getting-cannot-open-permission-denied-when-trying-to-restore-cache/14063/4 "2017-07-10T17:07:32Z")

</div>

Two things I see here.

1. `save_cache` isn’t properly indented. I assume that was just a copy & paste typo?

2. Clearly there’s permission issues. Maybe setting more permissive permissions on those directories before restore would help. my recommendation however would be to not install everything globally. The build environment gives you isolation and is throwaway. Installing locally within the user directory as much as possible would make things simpler. For example, here’s a post on Stack Overflow on using a local mocha binary instead of installing globally: [https://stackoverflow.com/questions/9722407/how-do-you-install-and-run-mocha-the-node-js-testing-module-getting-mocha-co#24497202](https://stackoverflow.com/questions/9722407/how-do-you-install-and-run-mocha-the-node-js-testing-module-getting-mocha-co#24497202)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:39am UTC](https://discuss.circleci.com/t/getting-cannot-open-permission-denied-when-trying-to-restore-cache/14063/5 "2018-06-18T11:39:40Z")

</div>


