help icon indicating copy to clipboard operation
help copied to clipboard

npm install issue

Open gianbuschor opened this issue 3 years ago • 10 comments
trafficstars

Details

For some reason it always generates an error when i try to install npm, can someone help me?

Gians-MacBook-Pro:metaplex gianbuschor$ npm install -g npm
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! dest /usr/local/lib/node_modules/.npm-i9nnxROI
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'
npm ERR!  [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/npm' -> '/usr/local/lib/node_modules/.npm-i9nnxROI'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/usr/local/lib/node_modules/npm',
npm ERR!   dest: '/usr/local/lib/node_modules/.npm-i9nnxROI'
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!     /Users/gianbuschor/.npm/_logs/2022-06-17T14_26_10_117Z-debug-0.log
Gians-MacBook-Pro:metaplex gianbuschor$ 

Node.js version

v16.15.1

Example code

npm install -g npm

Operating system

MacOS

Scope

installation

Module and version

Not applicable.

gianbuschor avatar Jun 17 '22 14:06 gianbuschor

The error is self-explanatory here, the installation process was rejected by your operating system due to insufficient permissions.

When you install npm packages globally (using the --global flag, or -g for short), you're telling the npm package manager to install the provided package globally so it can be accessed everywhere (this is mostly used when the npm packages provide a CLI, so installing them globally is the way to make them work by adding them to the PATH).

These operations require the user to be root/administrator, the way to run the command as root/administrator depends on the operating system, I'm going to list them for the most popular ones (you can look up how to achieve this in the OS you use if it's not listed here):

For both Linux* and macOS, you need to run the command with the sudo command, to indicate you're running the command as root:

$ sudo npm i -g npm

And enter the root password to run the command as root.

*: Linux is not an operating system on its own, what is referred to here are the Linux distributions, such as Ubuntu, Fedora, Linux Mint, Arch Linux, and many others.

For Windows, you need to open the terminal as Administrator (you can see how to do that here) and run npm i -g npm.

VoltrexKeyva avatar Jun 17 '22 22:06 VoltrexKeyva

I had the same problem in Windows, I used this ('npm i -g uuid') to install (uuid) and it was fixed, thank you.

imansabet avatar May 13 '23 08:05 imansabet

Looks like npm i -g npm worked for me as well, thank you.

Thyplozix avatar May 15 '23 13:05 Thyplozix

Was having same problem, after adding sudo it was solved, thanks man

juustAsh avatar May 19 '23 01:05 juustAsh

Was having same problem, after adding sudo it was solved, thanks man

sudo can cause potential security risks if used in the long run.

fatima-irshad avatar Sep 24 '23 18:09 fatima-irshad

To check the location of the package:

npm config get prefix

Then run this :

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Enter the password and run installation commands

It worked for me.

elfbrtc avatar Nov 23 '23 12:11 elfbrtc

The prefix isn’t necessarily the location of the package; you may want npm root -g.

ljharb avatar Nov 23 '23 14:11 ljharb

@elfbrtc you are a lifesaver!! Thank you so much!!

docentDavid avatar Jan 11 '24 16:01 docentDavid

So I have my permission set to read/write on linux for this whole directory but I'm still getting the error. Its on a mounted SMB directory so I don't know if that would mean I need to do something different.

wadert3 avatar Feb 11 '24 01:02 wadert3

To check the location of the package:

npm config get prefix

Then run this :

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Enter the password and run installation commands

It worked for me.

Thank you, It worked for me toooo

imhalid avatar Mar 11 '24 08:03 imhalid

This issue appears to be resolved. If you disagree, please let me know or have a member of the triage team reopen it.

avivkeller avatar Apr 21 '24 00:04 avivkeller