-1

I'm trying to use npm install to install a package but I keep getting below error.

I tried updating and downloading again from root but nothing seems to work.

hackathonday1-2 git:(save-button) ✗ npm install file-saver --save

npm WARN checkPermissions Missing write access to /home/salman/node_modules/axios npm WARN checkPermissions Missing write access to /home/salman/node_modules/coffeescript npm WARN checkPermissions Missing write access to /home/salman/node_modules/coffee-script npm WARN checkPermissions Missing write access to /home/salman/node_modules/file-saver npm WARN checkPermissions Missing write access to /home/salman/node_modules/materialize-css npm WARN enoent ENOENT: no such file or directory, open '/home/salman/package.json' npm WARN salman No description npm WARN salman No repository field. npm WARN salman No README data npm WARN salman No license field.

npm ERR! code EACCES npm ERR! syscall access npm ERR! path /home/salman/node_modules/axios npm ERR! errno -13 npm ERR! Error: EACCES: permission denied, access '/home/salman/node_modules/axios' npm ERR! [Error: EACCES: permission denied, access '/home/salman/node_modules/axios'] { npm ERR! stack: "Error: EACCES: permission denied, access '/home/salman/node_modules/axios'", npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/home/salman/node_modules/axios' npm ERR! } npm ERR! npm ERR! The operation was rejected by your operating system. npm ERR! It is likely you do not have the permissions to access this file as the current user npm ERR! npm ERR! If you believe this might be a permissions issue, please double-check the npm ERR! permissions of the file and its containing directories, or try running npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in: npm ERR!
/home/salman/.npm/_logs/2019-09-24T03_37_30_909Z-debug.log

Hardik Upadhyay
  • 2,639
  • 1
  • 19
  • 34
salman.dev
  • 1
  • 1
  • 1

3 Answers3

2

If there is a permission error on Linux for npm install, you can try to include sudo at the beginning of command. sudo npm install. Also make sure node.js is installed globally on your machine. Also make sure you have a package.json folder.

Dylan T
  • 139
  • 11
1

It's simply complaining about the fact that you don't own the folders /home/salman/node_modules/axios, /home/salman/node_modules/file-saver etc. Since it is your home directory, there really shouldn't be any directory or files that you don't own in /home/salman. My guess is that this happened because you ran npm with sudo causing it to create some files in your home folder that is owned by root instead of salman.

To fix the permission issue simply retake ownership of the node_modules folder:

cd /home/salman
sudo chown -R salman:salman node_modules

The -R flag makes chown recursively set you as the owner to all files and subfolders in the directory.

Side note: you really shouldn't use your home directory as your npm project directory. Do npm install in individual project directories. Yes, this wastes disk space but disk space is cheap and can freely be wasted. Even if you have 10 node.js projects you are unlikely to use more than 5GB of disk space even though there are lots of duplicate code files. A single HD movie is sometimes larger than that. Typical disk space usage for code is around 2GB.

slebetman
  • 109,858
  • 19
  • 140
  • 171
0
sudo chown -R $USER /home/salman/node_modules

This command is useful.. Run it on your system..