17

I'm getting a weird error:

Unhandled rejection Error: EACCES: permission denied, mkdir '/home/ubuntu/.npm/_cacache/index-v5/14/36'atus

I just install npm (6.4.1) and node (11.2.0) on an AWS instance without problems. I installed create-react-app globally. The error says This is an error with npm itself.

I'm kind of at a loss. I created the directory /home/ubuntu/.npm/_cacache/index-v5/14 and it still wouldn't succeed. I obviously own and have write permissions in /home/ubuntu.

It looks like it succeeds with sudo. why ?

Edit: ubuntu:ubuntu owns the current and parent directory (I'm in /home/ubuntu/workspace)

4
  • Try installing NodeJS with NVM. You won't face problems with permissions Commented Nov 24, 2018 at 6:32
  • Try on the command line the following shell command: mkdir - p '/home/ubuntu/.npm/_cacache/index-v5/14/36' however, make sure you run the command with the same user ID that you use for the installation. That is just for a quick test! Ops, one more thing to add. You mentioned that you have the answer already :) "It looks like it succeeds with sudo." OK, sudo has write privileges across the entire file system. Commented Nov 24, 2018 at 6:40
  • What is the owner and permission of this directory, and the recursively parent directory? Commented Nov 24, 2018 at 6:44
  • added comment, current users owns (and as I said has write permissions) in the current directory Commented Nov 24, 2018 at 7:28

11 Answers 11

41

TL;TR

Run:

sudo chown -R $USER:$USER '/home/REPLACE_WITH_YOUR_USERNAME/.npm/'

On Linux OS NPM and NodeJS are installed globally with sudo and the owner of that files is the root and usually a user can only read/execute that packages. When NPM is stalled a ~/.npm/ folder is created by the root. By running create-react-app you are executing the command as user and create-react-app is trying to modify something in the ~/.npm/ directory which is owned by the root and not to current user. You need to change the owner of that directory to you, so you can modify it without sudo privileges.

Often similar thing happens when you install NPM package with sudo e.g. sudo npm install <package> --save. Again the newly installed package in owned by the root and for example when you try to update/modufy/delete your project without sudo infrnt of NPM you will have similar permission error. In these cases navigate to your project directory and change its owner by running:

sudo chown -R $USER:$USER .
Sign up to request clarification or add additional context in comments.

3 Comments

+1 .... apparently when the first thing I install is with sudo and -g the /home/user/.npm folder isn't owned by me.
+1. . . thanks for the explanation and answer (newbies like me please change 'home/ubuntu/.npm/' to your own username)
I'm getting illegal group name? chown: a1621406: illegal group name
8

This problem on a Mac

Working from Reactjs's Getting Started documentation.

The Environment

  • OSX Mojave 10.14.3
  • NodeJS v10.15.0

The Error

  • Command
    npx create-react-app my-app
    
  • Output
    Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/caseywise/.npm/_cacache/index-v5/ae/73'instal
    

The Fix

recursively change owner:group on caseywise's NPM preferences directory

sudo chown -R caseywise:staff '/Users/caseywise/.npm/'

Comments

4

New way of installation will resolve the issue.

According to the latest react documentation follow below steps to create react app

npx create-react-app my-app
cd my-app
npm start

Note(from ReactJS Team): If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.

Refer official documentation: https://facebook.github.io/create-react-app/docs/getting-started

Comments

4

I was also facing create-react-app: Permission denied issue with ubuntu 18.04 .I have resolved this issue.

Please execute few commands.

  1. Completely uninstall nodejs, npm

     sudo apt-get remove nodejs
     sudo apt-get remove npm
    
  2. Check for any .npm or .node folder and delete those.

     which nodejs
     which node
    
  3. Install Node.js

     sudo apt update
     sudo apt install nodejs
    
  4. The nodejs package contains the nodejs binary as well as npm, so you don’t need to install npm separately.

    Check nodejs and npm version.

     nodejs --version #v12.22.6
     npm --version    #6.14.15
    
  5. Create react-app.

     npm init
     npx create-react-app "your-app-name"
    

Comments

3

Check the owner of the file with ls -l /problem/dir/. The owner is probably set to root, instead of myUserName (i.e. TWoody).

You will want to change owner of the .npm/ globally first with chown:

sudo chown -R $USER: ~/.npm/.

And if this issue has crept into other /build/ directories after running npm run build, you can go to those directories and run the same command:

sudo chown -R $USER: ./problem/dir/

Note that the chown command is using the -R flag to change the user ID and/or group ID for the hierarchies rooted in the files instead of just the files themselves. Also note that the argument $USER: is taking your user name (i.e. myUserName, TWoody) and replacing the "group" ID (the second argument of null) of root.

Comments

2

Remove or rename /home/ubuntu/.npm/_cacache/

Comments

0

I have same error on Mac catalina 10.15

You must use sudo, because root is the owner of npm folder, user try to modify some file under npm folder, must run as root by sudo.

The fix is:

            sudo dojo create app --name hello-world

Comments

0
sudo chown -R your_user ~/your_projects_directory

1 Comment

Code dumps do not make for good answers. You should explain how and why this solves their problem. I recommend reading, "How do I write a good answer?"
0

Use this command :

sudo chown -R 1000:1000 "/home/user/.npm"

Comments

0

In my case, with Windows WSL 2, switching to 'node' user using 'su node' fixed this 'sh: 1: create-react-app: Permission denied' issue. The error was coming when the command 'npx create-react-app test-app' was being executed via 'root'.

Comments

0

As mentioned above and in the error itself, the issue here is the gap between regular user and su user. The interesting part is, this issue occurs even when you run with sudo permissions i.e. sudo npx create-react-app app-name, from what I could gather this happens because the npx command is run in sudo but create-react-app is run as a regular user.

So another solution would be

sudo npm install -g create-react-app
create-react-app app-name
or
if needed sudo create-react-app app-name(this option not preferred mainly since further activity inside app like npm run start or others might also need usage of sudo)

Why I prefer this option is, I would rather have any global npm installation under sudo and only local npm installations under regular user. THis way I dont have to change permissions to the global npm directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.