Error while updating npm version - node.js

When I try:
npm i -g npm to udpate
I get following error:
npm ERR! code 1
npm ERR! Command failed: /usr/local/bin/git clone -q git://github.com/jonschlinkert/resolve-file.git /Users/my/.npm/_cacache/tmp/git-clone-d70e67af
npm ERR! /Users/my/.npm/_cacache/tmp/git-clone-d70e67af/.**git: Permission denied**
This indicates that Git is not authorized enough. I try to use sudo to execute, and the execution result is the same.

Use sudo command with npm command. It needs permissions.
Try this command:
sudo npm i -g npm#latest

In this case, npm with sudo cause npm is global mode
sudo npm i -g npm

your code is wrong. You can refer here or This also can use.
sudo npm i -g npm#latest

Related

I am trying to install node locally following error occurs. I tried reinstalling node several times but still it shows error

I get this error when I try to install node
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! C:\Users\lenovo\AppData\Roaming\npm-cache\_logs\2020-08-29T13_30_35_085Z-debug.log
try this first before installing node.
sudo npm cache verify
sudo npm cache clean --force
After installing verify your installation:
node --version
several things you can try are following
sudo npm cache clean --force
trying changing ownership of npm and try npm latest
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) /usr/local/lib
sudo chown -R $(whoami) /usr/local/bin
npm install -g npm#latest
give it a try by clearing up the proxy, maybe you're behind proxy
npm config set proxy null
npm config set https-proxy null
npm config set registry http://registry.npmjs.org/
Lately i would like to recommend you to use the NVM package. it is not the solution to your answer directly but its a great way to manage and have different node/npm environments
https://davidwalsh.name/nvm

Failed to install angular cli using command line

I was trying to install angular cli using the command.
sudo npm install -g #angular/cli#latest
But it throws the following error:
npm ERR! path /usr/bin/ng<br>
npm ERR! code EEXIST<br>
npm ERR! Refusing to delete /usr/bin/ng: ../lib/node_modules/angular-cli/bin/ng symlink target is not controlled by npm /usr/lib/node_modules/#angular/cli<br>
npm ERR! File exists: /usr/bin/ng<br>
npm ERR! Move it away, and try again.<br>
npm ERR! A complete log of this run can be found in:
npm ERR! /home/sachin/.npm/_logs/2018-11-06T13_58_33_153Z-debug.log
I have tried the following command
sudo npm cache clear --force
sudo rm -rf /usr/local/bin/ng
But got the same above error every time.
Try :
sudo npm uninstall -g #angular/cli
sudo npm cache clean
sudo rm -rf /usr/bin/ng => Option to ensure
sudo npm i -g #angular/cli#latest

Error while running (npm install -g #angular/cli) in mac

I'm trying to install angular/cli and when I run
npm install -g #angular/cli
in the terminal I come up with these error messages, furthermore, I tried to use sudo as a prefix but again not a positive result.
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#github.com/angular/cli.git
npm ERR!
npm ERR! Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/username/.npm/_logs/2018-10-06T04_44_40_632Z- debug.log
npm packages should be installed without sudo in macos
Infact sudo should be never be used unless tinkering with system wide
permissions. Node puts npm packages in a specific folder, usually
/usr/local/lib/node_modules. But the trouble is you need sudo
permissions to write here. This leads to an endless use of
non-requisite sudo permissions. This location is what we need to
change and here are handy terminal commands to achieve the same:
mkdir ~/.npm
npm config set prefix ~/.npm
nano ~/.bashrc
export PATH="$PATH:$HOME/.npm/bin"
source ~/.bashrc
Quoted from here: https://medium.com/#Mandysidana/using-npm-install-without-sudo-2de6f8a9e1a3
Finally, I found the answer
Here is the code just run in terminal:
sudo npm install -g #angular/cli

npm install permission denied (macOS)

To install a Bootstrap theme I want to run npm install. However I always receive a permission denied error.
I already tried nvm and then switched with nvm use 10.9.0 to run npm install.
I also tried sudo chown -R $(whoami) ~/.npmand sudo chown -R $USER /usr/local/lib/node_modules. Neither solved it and now I am bit out of ideas how I can continue. I use macOS High Sierra.
Marcs-MBP-3:masterclass Marc$ npm install
npm WARN deprecated gulp-uglifyjs#0.6.2: Since gulp-sourcemaps now works, use gulp-uglify instead
npm WARN deprecated babel-preset-es2015#6.24.1: 🙌 Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
npm WARN deprecated browserslist#1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN checkPermissions Missing write access to /Users/Marc/Desktop/Dev/masterclass/node_modules
npm ERR! path /Users/Marc/Desktop/Dev/masterclass/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/Users/Marc/Desktop/Dev/masterclass/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/Users/Marc/Desktop/Dev/masterclass/node_modules']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/Users/Marc/Desktop/Dev/masterclass/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/Marc/Desktop/Dev/masterclass/node_modules' }
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 (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Marc/.npm/_logs/2018-08-22T12_46_51_786Z-debug.log
For Mac;
Run this on the Terminal >
sudo chown -R $USER /usr/local/lib/node_modules
Check permissions of your project root with ls -l /Users/Marc/Desktop/Dev/masterclass/. If the owner is not $USER, delete your node_modules directory, try changing the owner of that directory instead and run npm install again.
cd /Users/Marc/Desktop/Dev
rm -rf ./masterclass/node_mdoules/
chown -R $USER ./masterclass/
cd masterclass
npm install
I tried everything in this thread with no luck on Big Sur, but then I tried this:
sudo npm install -g yarn
And it worked!
KIndly run the below commands:
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.
For me it was,
npm cache clean --force
rm -rf node_modules
npm install
I tried deleting manually but didn't help
I did this for nodemon and it work
sudo chown -R $USER /usr/local/lib/node_modules
then install the packages that you need
I was having a similar issue, but the accepted answer did not work for me, so I will post my solution in case anyone else comes along needing it.
I was running npm install in a project cloned from GitHub and during the clone, for whatever reason the write permission was not actually set on the project directory. To check if this is your problem, pull up Terminal and enter the following:
cd path/to/project/parent/directory
ls -l
If the directory has user write access, the output will include a w in the first group of permissions:
drwxr-xr-x 15 user staff 480 Sep 10 12:21 project-name
This assumes that you're trying to access a project in the home directory structure of the current user. To make sure that the current user owns the project directory, follow the instructions in the accepted answer.
I entered the following:
cd /Users/Marc/Desktop/Dev
rm -rf ./masterclass/node_mdoules/
chown -R $USER ./masterclass/
cd masterclass
npm install
once this was completed the results indicated warnings and one notice instead of previous result of no permission and error.
I then entered the following:
% sudo npm install --global firebase-tools
my result was success upon completion of the last terminal entry.
I have same problem because i install it from pkg, and i solve this problem use below step:
1. sudo rm -rf /usr/local/lib/node_modules/npm/
2. brew doctor
3. brew cleanup --prune-prefix ( or sudo rm -f /usr/local/include/node)
4. brew install node
i use this command :
sudo npm install -g #angular/cli
Gave password and worked for mw. Took 10 secs to install angular
NPM_CONFIG_PREFIX=~/.npm-global
Copy this line into ur terminal, then hit enter. Then install the necessary packages you need WITHOUT the term "sudo" in front of npm.
i.e.,
npm install -g jshint
the only thing that work on me sudo npm i -g clasp --unsafe-perm
Just do :
sudo npm install -g #sanity/cli && sanity init
it will ask sudo password and you are good to go
That is because you dont have the "node modules". You can install with this code:
npm install -g node-modules
then, create your react app with npm init react-app my-app
For Macs running Big Sur or Monterey:
sudo chown -R $USER /usr/local/bin
Run on macOS Terminal:
sudo chown -R $USER /usr/local/bin
It will ask for the password then you're good to go!
Hope this helps.
Ok my problem was that I thought I was installing on the path:
/Users/mauro/Documents/dev/react
Where my project was setup, but instead I was doing it on:
Users/mauro/Documents/dev/
One path higher and that is why it did not perform the installation in my case.
I simply did: cd react and voila I was able to install without problem

Different version of npm when using sudo?

when I tried to update npm, I found that command returns Permission deny:
npm install npm -g
Then I tried:
sudo npm install npm -g
Then npm has been updated, but when I tried npm -v and sudo npm -v, they show different version:
npm -v //3.10.10
sudo npm -v //5.1.0
How can I make them always in the same version? It also happened on command 'node -v'. I am using fedora.

Resources