I wanted to do npm install -g
. As it didn't work due to permissions I took the approach suggested from the accepted answer in https://stackoverflow.com/questions/47252451/permission-denied-when-installing-npm-modules-in-osx
Change the owner of npm's directories to the name of the current user (your username):
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
then I could run my npm install -g
. But this is not where the story ends. I wanted to install another package with npm. (npm install identicon
).
I received the following error
npm does not support Node.js v12.0.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
....
And now I receive the same error over and over again, whenever I use a npm
command.
On SO someone else had this issue https://stackoverflow.com/questions/56805007/npm-warn-npm-does-not-support-node-js-v12-4-0?noredirect=1&lq=1 and the accepted answer suggested
Fix /usr/local permissions:
sudo chown -R
id -un:
id -gn/usr/local
Clean npm cache and uninstall it:
npm cache clean -f
npm -g uninstall npm
Reinstall node (with npm)
brew reinstall node
Upgrade npm:
npm -g i npm
But the very first command failed:
chown: /usr/local: Operation not permitted
In case this helps:
/usr/local root# ls -la
total 0
-rw-r--r-- 1 myuser staff 0 Sep 20 2019 .com.apple.installer.keep
drwxrwxr-x 2 myuser staff 64 Apr 24 2019 Caskroom
drwxrwxr-x 103 myuser staff 3296 Nov 17 17:31 Cellar
drwxrwxr-x 3 myuser staff 96 Nov 17 17:25 Frameworks
drwxrwxr-x 22 myuser staff 704 Jan 14 05:49 Homebrew
drwxrwxr-x 409 myuser staff 13088 Jan 14 05:49 bin
drwxrwxr-x 10 myuser staff 320 Nov 17 17:23 etc
drwxrwxr-x 192 myuser staff 6144 Nov 17 17:33 include
drwxrwxr-x 620 myuser staff 19840 Nov 17 17:33 lib
drwxr-xr-x 5 myuser staff 160 Mar 24 2019 man
drwxrwxr-x 124 myuser staff 3968 Nov 17 17:34 opt
drwxr-xr-x 3 myuser staff 96 Mar 24 2019 remotedesktop
drwxrwxr-x 12 myuser staff 384 Nov 17 17:27 sbin
drwxrwxr-x 34 myuser staff 1088 Nov 17 17:34 share
drwxr-xr-x 4 myuser staff 128 Mar 24 2019 texlive
drwxrwxr-x 4 myuser staff 128 May 16 2021 var
I want to use npm again and have my permissions fixed. Maybe someone can point out good ressources for beginners, which can guide me through the process, when I experience something similar. Thank you.
My macbookpro: macOS Catalina (10.15.7)
sudo chown -R $(id -un):$(id -gn) /usr/local/*
should work. But please runls -l /usr/local/bin
first and add the result to the quesiton (instead of the listing of/var/db/sudo
which doesn't matter here).ls -l /usr/local/bin
is couple hundred entries long, is this really right (feels wrong). Do you want to see a specific entry or a couple of entries?