NPM command can't work it will pop out Permission denied - npm-install

I'm try to check on terminal
hauying#hauying-yoga-linux:~$ npm -v
bash: /usr/bin/npm: Permission denied
and I try add sudo
hauying#hauying-yoga-linux:~$ sudo npm -v
sudo: npm: command not found
and i find name
hauying#hauying-yoga-linux:~$ find -name npm
./npm
I try this commeand
hauying#hauying-yoga-linux:~$ whereis npm
npm: /usr/bin/npm /usr/share/npm /usr/share/man/man1/npm.1.gz
/usr/share/man/man3/npm.3.gz
someone can help me?

Related

npm: Unhandled rejection Error: EISDIR: illegal operation on a directory, open ‘/Users/me/.npm/_cacache/content-v2/sha512/b3/da’

On my Mac, I just updated my working npm version from 5.6 to 6.9 thusly:
sudo npm i -g npm
Then I tried to install cordova like this:
sudo npm install -g cordova
And get
Unhandled rejection Error: EISDIR: illegal operation on a directory,
open '/Users/me/.npm/_cacache/content-v2/sha512/04/89'
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/me/.npm/_logs/2019-04-02T11_50_57_678Z-debug.log
I tried to downgrade thusly:
sudo npm install -g npm#6.4.1
but this fails with hundreds of lines like this:
npm WARN tar EISDIR: illegal operation on a directory, open '/tmp/npm-30934-a3ac319a/unpack-28da209e/bin/node-gyp-bin'
Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/me/.npm/_cacache/content-v2/sha512/99/72'
I also tried making sure the ownership was correct:
sudo chown -R $(whoami) ~/.npm
There are lots of posts of various EISDIR (error is a directory) problems for other directories (such as /usr/lib/modules), but no solutions seem to work.
Also, the npmrc file does not seem to exist. If I do:
npm config ls -l
globalconfig = "/usr/local/etc/npmrc"
userconfig = "/Users/me/.npmrc"
but neither file exists.
Note, I dont have homebrew, and didnt install it that way (I usually do manual installs).
I also tried this:
sudo npm cache clean -f
This did not help.
What else can I try? should I try deleting the ~/.npm dir?
Looking for a way to uninstall node, I found many old posts with long and sometimes conflicting lists of files to remove. Not sure if this will make it worse.
Any suggestions?
I think I have found a solution. I did the following:
installed node from the Mac pkg installer from https://nodejs.org/en/ This downgraded npm to 6.4.1 which is the version before EISDIR problems start apparently.
chmod -R 777 ~/.npm/_cacache // yes, this is not good
chown -R me ~/.npm/_cacache
After this, I could install cordova using "sudo npm install -g cordova" without errors.
I had the same problem when I upgraded to npm 6.9.0. You have to upgrade node to the last version:
brew reinstall node
At this time I have installed the latest available version for Mac OS Mojave (node: v11.14.0 and npm 6.9.0).
After node upgrade, I was able to install packages globally again.
Changing the ownership of files and then avoiding the use of sudo is a possible workaround for EISDIR with global installs using sudo. I suppose you have installed to default location folder:
sudo chown -R <user> ~/.npm
sudo chown -R <user> /usr/local/lib
sudo chown -R <user> /usr/local/bin
After this sequence, it worked to me.

Error: node_modules directory is missing. Please run `npm install` in your project directory

expo start
[21:03:34] Starting project at /home/sadaif/Documents/React-Native-App/my
[21:03:35] Expo DevTools is running at http://localhost:19002
[21:03:35] Opening DevTools in the browser... (press shift-d to disable)
[21:03:41] Error: node_modules directory is missing. Please run `npm install` in your project directory.
[21:03:41] Couldn't start project. Please fix the errors and restart the project.
[21:03:41] Set EXPO_DEBUG=true in your env to view the stack trace.
I run this command npm install but noting happened
then i run these commands
rm -rf node_modules
rm package-lock.json
npm cache clear --force
npm install
When I run command expo start then this error show in the terminal .I'm Using first time expo cli i m a beginner so that's why have no idea how to fix this issue if anyone know please help me.
either you are using Mac or Ubuntu the directory you have created the project in needs superuser permissions to modify it.
either run all commands with sudo or change the ownership
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
or re-install the node with
npm install -g node#latest --unsafe-perm

On npm install: Unhandled rejection Error: EACCES: permission denied

I have managed to corrupt my npm install, and whenever I try to install packages using npm install, I receive error messages along these lines:
Unhandled rejection Error: EACCES: permission denied, open '/Users/marknorgate/.npm/_cacache/tmp/a449402d'
I have tried reinstalling node & npm, and I have also tried to relocate my npm cache elsewhere using these instructions but nothing works.
How can I get it working?
Restore ownership of the user's npm related folders, to the current user, like this:
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) ~/.config
This happens if the first time you run NPM it's with sudo, for example when trying to do an npm install -g.
The cache folders need to be owned by the current user, not root.
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
This will give ownership to the above folders when running with normal user permissions (not as sudo).
It's also worth noting that you shouldn't be installing global packages using SUDO. If you do run into issues with permissions, it's worth changing your global directory. The docs recommend:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Then updating your PATH in wherever you define that (~/.profile etc.)
export PATH=~/.npm-global/bin:$PATH
You'll then need to make sure the PATH env variable is set (restarting terminal or using the source command)
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
sudo npm cache clean --force --unsafe-perm
and then npm i goes normally
Above answer didn't work for me. Just try to run your command with --unsafe-perm.
e.g
npm install -g node#latest --unsafe-perm
This seems to solve the problem.
If none of suggestions in answers worked out, try the following command: npm cache clear --force. It worked for me.
I found it at https://github.com/vuejs/vue-cli/issues/1809.
change ownership
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
worked for as i installed package using sudo
just create folders _cache/tmp under .npm manually at location /Users/marknorgate/.npm/_cacache/tmp and run your command with administrator access
sudo npm install --unsafe-perm=true --allow-root
This was the one that worked for me
Simply do sudo npm cache clean --force --unsafe-perm and npm i will go normally.
This worked for me!
Resolving EACCES permissions errors when installing packages globally
Try using this:
On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
Now use npm install it should work.
you can try following command for expo :
sudo chown -R $USER:$GROUP ~/.expo
as per npm community
sudo npm cache clean --force --unsafe-perm
and then npm install goes normally.
source: npm community-unhandled-rejection-error-eacces-permission-denied
Simply run on terminal : sudo chown -R $(whoami) ~/.npm
This worked for me !!
This one works for me:
sudo chown -R $(whoami) ~/.npm
I did not use the -g because I am the only user. I used a MacBook Air.
sudo npm install -g #angular/cli
use this. it worked for me

No such file or directory error for npm

I think I have installed npm.. But when I try to type npm -v ,it shows
-bash: /usr/local/bin/npm: No such file or directory
How to fix that.. node -v works fine... The terminal shows
v0.12.4
Can anyone help me ...
I have fixed that problem by reinstall node and npm. For mac user, try to type
sudo curl -L npmjs.org/install.sh | sudo sh
Hope it works.

How to fix EACCES issues with npm install

Some of my node modules get installed but there are always these sort of issues on this particular linux mint machine
npm install
npm ERR! Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json'
npm ERR! { [Error: EACCES, open '/home/me/.npm/semver/3.0.1/package/package.json']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/me/.npm/semver/3.0.1/package/package.json',
npm ERR! parent: 'gulp' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
This code fix it for me.
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
UPDATE. See
this answer
for a better way.
You have to set correct permissions (ownership) so npm can access your (sub)directories with your normal user permissions:
sudo chown -R $USER <directory>
where in your case <directory> is /home/me and -R is for recursive to also change ownership of all your subdirectories, which is exactly what you want. That should fix the EACCESS issue.
Sadly the advise to run the command as root/Administrator is wrong here.
You want to avoid running npm with sudo ever, as recommended by the npm creator Isaac Schlueter:
I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.
See here for more details.
Add sudo before npm install . It will permit access to write .
sudo npm install [name of package].
Try to use "sudo npx create-react-app app-name"
it may still show error because some dependencies may be mising but a directory and the necessary files maybe created.
Set the correct permission to access the necessary directories.
In my case (Node & NPM Installation via Brew) on BigSur:
sudo chown -R $USER /Users/YOUR_USERNAME/node_modules
If you are still facing problem after running :
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
Run the npm install command with :
--unsafe-perm
which will help you in installing the package with out any problem.
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory.
Back up your computer.
On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
To test your new configuration, install a package globally without using sudo:
npm install -g jshint
(ref: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally)
Running the code in sudo mode have fixed the problem for me
$ sudo npm install -g nativefier
And if you have related issues like package unmet dependencies check out this link
in windows run cmd as administrator and then try:
npm install -g <package-name>
in mac os or linux try:
sudo npm install -g <package-name>
I understand one might be suspicious about changing the ownership of folders situated in the system files. But it's completely safe, they are meant to host processes that you can use without sudo. So I prefer this solution because it's good and will guarantee compatibility after.
sudo chown -R $USER /usr/local/bin
sudo chmod -R 0775 /usr/local/bin
sudo chown -R $USER /usr/local/lib/node_modules
sudo chmod -R 0775 /usr/local/lib/node_modules
If you installed a new version of node.js, you could still get some error. Try deleting the npm cache:
sudo npm cache clear
To permanently fix this problem, please run:
sudo chown -R 1000:1000 "/home/$USER/.npm"
sudo npm install -g create-react-app
just adding sudo before nmp install will give superuser privilages to run npm and that would not cause any erros while it want to alter a file or access it. well, i hope this might help you!
I had the Similar Problem when I typed:
npm install -g create-react-app
The Terminal replied:
npm ERR! code EACCES
....
So I add "sudo" like This:
sudo npm install -g create-react-app
And problem Solved!! :-)
(So I am agree with "chethan chandan" about using "sudo")