help
help copied to clipboard
npm install issue
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.
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.
I had the same problem in Windows, I used this ('npm i -g uuid') to install (uuid) and it was fixed, thank you.
Looks like npm i -g npm worked for me as well, thank you.
Was having same problem, after adding sudo it was solved, thanks man
Was having same problem, after adding sudo it was solved, thanks man
sudo can cause potential security risks if used in the long run.
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.
The prefix isn’t necessarily the location of the package; you may want npm root -g.
@elfbrtc you are a lifesaver!! Thank you so much!!
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.
To check the location of the package:
npm config get prefixThen 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
This issue appears to be resolved. If you disagree, please let me know or have a member of the triage team reopen it.