NPM install permission denied error using root user

npm permission denied mac
npm install permission denied ubuntu
npm install permission denied, mkdir
install npm
npm install root user
using npm to install node
npm global install path
error: eacces: permission denied, rename

So I've made a fresh installation of npm/node on my local machine using NVM using root user and everything looks fine, now my issue is when I tried to install using npm install --unsafe-perm -verbose command on my project folder error displays in my terminal.

npm verb stack Error: Command failed: /usr/bin/git clone --depth=1 -q -b 0.0.7 https://github.com/Mango/emitter.git /root/.npm/_cacache/tmp/git-clone-28a98ad9
npm verb stack fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-28a98ad9': Permission denied
npm verb stack 
npm verb stack     at ChildProcess.exithandler (child_process.js:282:12)
npm verb stack     at ChildProcess.emit (events.js:182:13)
npm verb stack     at maybeClose (internal/child_process.js:957:16)
npm verb stack     at Socket.stream.socket.on (internal/child_process.js:378:11)
npm verb stack     at Socket.emit (events.js:182:13)
npm verb stack     at Pipe._handle.close [as _onclose] (net.js:598:12)
npm verb cwd /web/nbltv
npm verb Linux 4.15.0-29-generic
npm verb argv "/root/.nvm/versions/node/v10.1.0/bin/node" "/root/.nvm/versions/node/v10.1.0/bin/npm" "install" "--unsafe-per" "-verbose"
npm verb node v10.1.0
npm verb npm  v5.6.0
npm ERR! code 128
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b 0.0.7 https://github.com/Mango/emitter.git /root/.npm/_cacache/tmp/git-clone-28a98ad9
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-28a98ad9': Permission denied
npm ERR! 
npm verb exit [ 1, true ]

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-08-20T01_36_33_496Z-debug.log

NPM version - 5.6 NODE version - 10.1

Any help would be much appriciated. Thanks!

Chown down your node_modules & do not run as sudo.

You should always have ownership of the .npm directory as NPM will refuse installing native modules with sudo as this is a security risk for example.

Try sudo chown -R $(whoami) ~/.npm and see if this would work.

Or reinstall with a node version manager without root as recommended in the docs:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Getting Permission Denied Error when Installing with NPM · Issue , While trying to install a packge with npm (for example lodash) it fails with error message: npm Please try running this command again as root/Administrator. npm ERR! get a permissions access error still or at least I did. npm install without root permissions (Error while doing npm install as bamboo user) Bamboo working directories and source code is owned by 'root'

Creating a new global storage in your user space is the recommended way of preventing this error. Don't use sudo or change ownership of locations.

$ mkdir ~/.npm-global
$ npm config set prefix '~/.npm-global'
$ export PATH=~/.npm-global/bin:$PATH
$ source ~/.profile

However, since you're using npm 5.6, this might be more relevant to you:

npx: an alternative to running global commands

If you are using npm version 5.2 or greater, you may want to consider npx as an alternative way to run global commands, especially if you only need a command occasionally. For more information, see this article about npx.

Source: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

"npm ERR! Error: EACCES: permission denied" · Issue #14, If you see an EACCES error when you try to install a package globally, you can To minimize the chance of permissions errors, you can configure npm to use a To test your new configuration, install a package globally without using sudo :. Sounds like a problem related to your machine for me. Also, you should never use sudo in combination with npm. I'd guess your file permissions are broken in your npm folder, you may try: delete your npm cache. reset the permissions of your /Users/juniethreatt/.npm/ recoursively to your user.

@U-ways answer is very good but for people who use nvm rather than:

sudo chown -R $(whoami) ~/.npm

do

sudo chown -R $(whoami) ~/.nvm

this works form me

Resolving EACCES permissions errors when installing packages , The first time you try to install a package globally using npm, using the It's a permission error, which means you don't have write access to that folder. don't have permission to write to that folder, but root will be able to fix  I'm opening this issue because: npm is crashing. npm is producing an incorrect install. npm is doing something I don't understand. Other (see below for feature requests): What's going w

How to fix the "Missing write access" error when using npm, Learn to solve this npm error - Error: EACCES: permission denied, installing npm as a user other than root, it's a bad idea to install Node +  On a development machine, you should not install and run node with root permissions, otherwise things like npm link, npm install -g will need the same permissions. NVM (Node Version Manager) allows you to install Node without root permissions and also allows you to install many versions of Node to play easily with them.. Perfect for development.

Fixing your NPM installation, install a npm package npm i -g bash-language-server with sudo privileges and after downloading and extracting all file i am getting this error. sudo npm install --unsafe-perm=true --allow-root To install only the package which caused the issue: sudo npm install -g --unsafe-perm=true --allow-root eslint

EACCES: permission denied, access '/root/.npm' - support, npm install Error: EACCES: permission denied, access '/var/www/html' or try running npm ERR! the command again as root/Administrator (though this is not  To test your new configuration, install a package globally without using sudo: npm install -g jshint Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don’t want to modify ~/.profile ):