npm global install of ganache-cli fails (because of sudo/permissions) - node.js

I have npm version 6.5.0 and node v10.10.0.
There have been no previous issues with npm global installs.
sudo npm install --global ganache-cli
npm ERR! code 128
npm ERR! Command failed: /usr/bin/git clone --depth=1 -q -b master https://github.com/ethereumjs/ethereumjs-abi.git /root/.npm/_cacache/tmp/git-clone-305900d8
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-305900d8': Permission denied
npm ERR!
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-12-12T20_49_21_325Z-debug.log

The basic problem is that globally installing packages with npm links them into directories under /usr/local/, which are typically owned by the root user.
Node Version Manager (nvm) is one way to circumvent such tricky permissions issues. It allows globally installed packages to be linked into directories in your home folder under ~/.nvm/versions/node/<version>
Using my package manager, I removed node and related software such as npm.
I used find /usr/local/ -name 'node_modules' to scour /usr/local/ for any vestiges of the packages I had previously installed globally with npm. Delete them all.
Then I installed nvm using the latest install script from https://github.com/creationix/nvm
In my case it was
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
I had to then link nvm into my environment path.
In my case, this meant manually editing my .bashrc profile to include this:
export NVM_DIR="/home/zack/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
From there, I was ready to get the most recent LTS version of node through nvm
nvm install --lts
Now globally installed packages can be installed without sudo because they are deposited under ~/.nvm/versions/node/v10.14.2/ and everything works perfectly!

Related

npm WARN: npm does not support Node.js v12.4.0

I've been getting the following warnings lately whenever I run any npm script:
npm WARN npm npm does not support Node.js v12.4.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11.
npm WARN npm You can find the latest version at https://nodejs.org/
It says that I should upgrade to a newer version, but v12.4 is the newest version. Even though the scripts run fine, I think there's no guarantee and something might break at any moment.
I've also tried updating npm in case there's a newer version using npm install npm -g but got the error:
npm ERR! path /usr/local/Cellar/node/12.4.0/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
npm ERR! [Error: EACCES: permission denied, access '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'] {
npm ERR! stack: 'Error: EACCES: permission denied, access ' +
npm ERR! "'/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/Cellar/node/12.4.0/lib/node_modules/npm'
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 (though this is not recommended).
Then I've seen that Homebrew version of npm can't be updated using npm itself, so I tried updating through Homebrew using brew upgrade npm but got this error:
Error: npm 12.4.0 already installed
For some reason Brew mixes up nodes and npms versions.
What am I doing wrong and how can I get rid of this warning?
What worked for me:
if you try running this command "npm cache clean -f" and it doesn't work,
on your windows machine(mine is windows 10)
access the "npm" and "npm-cache" folders in this location "~\AppData\Roaming\"
delete these two folders "npm" and "npm-cache".
go to your windows search bar and search for Node, right click to open file location, run the uninstaller to uninstall NodeJs.
then visit nodejs.org and download and install node again, if you've already downloaded it, visit the folder where you downloaded it to reinstall it.
after installation, check your version of npm by typing "npm -v" on your command terminal to see the new updated version of npm installed on your machine.
now you're all set, Happy coding.
Seems like you messed up with permissions in /usr/local.
Here is how to fix that:
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
That should bring npm#6.9.2.
You should avoid using sudo while installing software with brew or npm, that could cause issues like this.
If you have nvm you may have an issue in which your node version installed at a certain version didn't match.
For example, I accidentally used: npm i -g node --force resulting in my nvm v12.21.0 to point to v16.5.0 (the latest version of node at that time directly downloadable).
To solve: I ran:
Just for good measure brew uninstall nvm
brew install nvm.
nvm uninstall 12.21
nvm install 12.21
Just for good measure I ran npm i -g npm resulting in the latest version of npm installed on that virtual node.
After installing within some repo (using npm i) you may also want to check your: ~/.npmrc.
email=myemail#company.com
registry=https://artifactory.company.com/npm/npm/
always-auth=true
user-agent=npm/6.14.11 node/v12.21.0 darwin x64
_authToken=siofjwoirgiowrgnioaenrvoianeoiio32noi23nio23nio23nio
It should look something like this: (or you might not have any of that.
Had the same issue with Debian 10 (buster) when I tried installing the npm and node.js. They were incompatible and wouldn't update. This was what I found works for me.
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
The nodejs package was installed at a different path and I manually deleted the old package (in /usr/bin/) and added a symlink to point to the new one (in /usr/local/bin).
sudo rm /usr/bin/node
sudo ln -s /usr/local/node /usr/bin/node
This is the initial printouts from running the commands. The npm version updates from 5.8.0 to 8.1.2. But the nodejs version stayed at 10.24.0 even after reboot with hash -r.
None of the answers here worked. I had to delete the npm and npm-cache folders, then reinstall npm. Details here: npm does not support Node.js v12.18.3
After step 4 posted by Styx, and if node claims installation fo a newer version but npm -v keeps showing outdated version
Code for Mac and node installed with brew:
cd /usr/local/bin/
mv npm npm-backup
mv npx npx-backup
ln -s /usr/local/Cellar/node/14.2.0/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
ln -s /usr/local/Cellar/node/14.2.0/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
npm -version
6.14.5
I hit this issue and the steps above didn't work for me. I think it can happen if you try to upgrade Node or NPM without updating the other also. At least I think that's what happened to me.
I was trying to create a new Angular project and I had a very old version on my machine. I got an error to upgrade Node, so I bumped it to the latest version. After that I got the error running any npm command.
I resolved it simply by going to:
https://nodejs.org/en/download/
Getting the latest version and installing that in a pkg file (mac). After install was complete I was able to run everything. I'm guessing it worked because the versions of each mismatched, so one wouldn't run without the other being downgraded.
I also tried the brew option but I was getting other issues. My corporate machine sometimes blocks installations in that route, so it might work for others.
For Windows, this was driving me crazy, and all of the above solutions were not working, I would still get the old version of node showing for node -v.
For me simply killing the terminal window and starting it again resolved the issue. No amount of cache clearing worked until this. I know it sounds dumb, but that's what resolved this for me in the end. Hope this helps someone else not lose hours farting around with this.
I've have this issue in npm -v package,so you have to easy step in follow of solve this problem.
npm use stable
nvm use stable
nvm cache clear
nvm install stable --default
you can closed the terminal then check the `npm --version
Looks like a permission issue. Try with sudo

sudo: npm: command not found, while running npm with sudo

I installed nodejs v8.11.2 and npm v5.6.0 using the command nvm install 8.11.2.
When I opened my system after shutting it down for a while my system and wrote npm -v in the terminal, it said npm is not installed, and to install it with sudo apt install npm.
However when I again entered nvm install 8.11.2, it said that nodejs and npm are already installed and it began using it. Sometimes when opening a different terminal, npm -v says that npm is not installed. And later when I used the command sudo npm install, the output came:
sudo: npm: command not found
So I installed npm with sudo apt-get install npm, but it installed npm v3.5.2 and updating it with npm install npm#latest -g did nothing, i.e., it remained npm v3.5.2.
I need npm v5.6.0 for a project of mine and is clueless on how to get this issue sorted. Please help.
(nvm maintainer here)
sudo is not, and must not be, used with nvm. nvm is per-user, per-shell.
npm should not be installed by itself; it comes with node. You should apt-get remove it.
If nvm isn't being loaded properly on a new shell, try rerunning the install script, then file an issue on http://nvm.sh, and I'll be happy to help you directly.

npm install: Error: EACCES: permission denied, mkdir

I attempted to do a sudo npm install -g appium on Mac OS 10.12.5.
I get this error:
info Chromedriver Install Installing Chromedriver version '2.30' for platform 'mac' and architecture '64'
info Chromedriver Install Opening temp file to write chromedriver_mac64 to...
Error: EACCES: permission denied, mkdir
'/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/2017820-44752-12jfqpb.z2hd'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! appium-chromedriver#3.0.1 install: node install-npm.js
npm ERR! Exit status 1
npm ERR!
this is not a dup question, as this install attempt was with sudo, as the other one was not.
sudo npm install -g appium --unsafe-perm=true --allow-root
Worked for me
you are using npm so you have to use
sudo npm install --unsafe-perm
In unsafe mode with every command you run
hopefully, it will help
The -g option means install globally. When packages are installed globally, EACCES permission errors can occur.
Consider setting up npm to operate globally without elevated permissions. See Resolving Permission Errors for more information.
Option 1
The best way to avoid permission issues is to reinstall NodeJS and npm using a node version manager.
1. Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
You can close and reopen the terminal ou just open another terminal and check if nvm is installed properly with this command: command -v nvm.
2. To download and install the latest LTS release of NodeJS, run:
nvm install --lts
3. Set the newly installed NodeJS as the default environment:
nvm alias default lts/*
Option 2 (Does not apply for windows)
Change the owner of npm's directories to the current user:
sudo chown -R $(your_user) /usr/local/{lib/node_modules,bin,share}
sudo chown -R $(your_user) ~/.npm ~/.npmrc
I reinstalled Node/NPM. Problem solved.

sudo npm fails, env: node: No such file or directory

After uninstalling and reinstalling node and npm I can no longer run npm as sudo. This is on a Mac. I have tried the official node installer and brew.
It works from my user but any attempt to run sudo npm produces this error:
$ sudo npm
env: node: No such file or directory
npm most likely is installed at /usr/local, but /usr/local is not on the $PATH of the root user. You can configure sudo to allow the $PATH to be changed, but if you installed npm with Homebrew you shouldn't have to use sudo at all.

"message failed to fetch from registry" while trying to install any module

I can't install any node module from the npm.
npm install socket.io
The above command resulted to below output, it is not able to install socket.io
npm http GET https://registry.npmjs.org/socket.io
npm ERR! Error: failed to fetch from registry: socket.io
npm ERR! at /opt/node0610/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR! at cb (/opt/node0610/lib/node_modules/npm/lib/utils/npm-registry-client/request.js:32:9)
npm ERR! at Request._callback (/opt/node0610/lib/node_modules/npm/lib/utils/npm-registry-client/request.js:137:18)
npm ERR! at Request.callback (/opt/node0610/lib/node_modules/npm/node_modules/request/main.js:109:22)
npm ERR! at Request.<anonymous> (/opt/node0610/lib/node_modules/npm/node_modules/request/main.js:198:58)
npm ERR! at Request.emit (events.js:88:20)
npm ERR! at ClientRequest.<anonymous> (/opt/node0610/lib/node_modules/npm/node_modules/request/main.js:195:10)
npm ERR! at ClientRequest.emit (events.js:67:17)
npm ERR! at CleartextStream.<anonymous> (http.js:1134:11)
npm ERR! at CleartextStream.emit (events.js:67:17)
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Linux 2.6.18-194.el5
npm ERR! command "node" "/opt/node0610/bin/npm" "install" "socket.io"
npm ERR! cwd /opt/node0610/lib/node_modules
npm ERR! node -v v0.6.10
npm ERR! npm -v 1.1.0-3
npm ERR! message failed to fetch from registry: socket.io
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /opt/node0610/lib/node_modules/npm-debug.log
npm not ok
My NPM Version is :
[applmgr#dev node_modules]$ npm --version
1.1.0-3
My NodeJS Version is :
[applmgr#dev node_modules]$ node --version
v0.6.10
I had this issue with npm v1.1.4 (and node v0.6.12), which are the Ubuntu 12.04 repository versions.
It looks like that version of npm isn't supported any more, updating node (and npm with it) resolved the issue.
First, uninstall the outdated version (optional, but I think this fixed an issue I was having with global modules not being pathed in).
sudo apt-get purge nodejs npm
Then enable nodesource's repo and install:
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
Note - the previous advice was to use Chris Lea's repo, he's now migrated that to nodesource, see:
https://chrislea.com/2014/07/09/joining-forces-nodesource/
https://nodesource.com/blog/chris-lea-joins-forces-with-nodesource
From: here
https://github.com/isaacs/npm/issues/2119
I had to execute the command below:
npm config set registry http://registry.npmjs.org/
However, that will make npm install packages over an insecure HTTP connection. If you can, you should stick with
npm config set registry https://registry.npmjs.org/
instead to install over HTTPS.
I'm on Ubuntu. I used apt-get to install node. Npm was not included in that package, so it had to be installed separately. I assumed that would work, but apparently the npm version in the Ubuntu distribution was outdated.
The node wiki has this instruction:
Obtaining a recent version of Node or installing on older Ubuntu and other apt-based distributions may require a few extra steps. Example install:
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
After that, npm was already included and worked perfectly.
For me, it's usually a proxy issue, and I try everything:
npm config set registry http://registry.npmjs.org/
npm config set strict-ssl false
npm config set proxy http://myusername:mypassword#proxy.us.somecompany:8080
npm config set https-proxy http://myusername:mypassword#proxy.us.somecompany:8080
set HTTPS_PROXY=http://myusername:mypassword#proxy.us.somecompany:8080
set HTTP_PROXY=http://myusername:mypassword#proxy.us.somecompany:8080
export HTTPS_PROXY=http://myusername:mypassword#proxy.us.somecompany:8080
export HTTP_PROXY=http://myusername:mypassword#proxy.us.somecompany:8080
export http_proxy=http://myusername:mypassword#proxy.us.somecompany:8080
npm --proxy http://myusername:mypassword#proxy.us.somecompany:8080 \
--without-ssl --insecure -g install
You also need to install software-properties-common for add-apt-repository to work.
so it will be
sudo apt-get purge nodejs npm
sudo apt-get install -y python-software-properties python g++ make software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
One thing that has worked for me with random npm install errors (where the package that errors out is different under different times (but same environment) is to use this:
npm cache clean
And then repeat the process. Then the process seems to go smoother and the real problem and error message will emerge, where you can fix it and then proceed.
This is based on experience of running npm install of a whole bunch of packages under a pretty bare Ubuntu installation inside a Docker instance. Sometimes there are build/make tools missing from the Ubuntu and the npm errors will not show the real problem until you clean the cache for some reason.
This problem is due to the https protocol, which is why the other solution works (by switching to the non-secure protocol).
For me, the best solution was to compile the latest version of node, which includes npm
apt-get purge nodejs npm
git clone https://github.com/nodejs/node ~/local/node
cd ~/local/node
./configure
make
make install
There are now official instructions from joyent (primary nodejs backer). For Ubuntu:
sudo apt-get purge nodejs npm
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
For other unix distributions, osx and windows see the link. Note this will install both node and npm.
The only thing that worked for me on Elementary OS Luna, a Ubuntu Fork. I am on x86 architecture. I tried all the answers here but finally decided to install it from source.
First, make sure its not installed using the package manager:
sudo apt-get purge nodejs npm -y
I went to the download page to lookup the latest source & download it, http://nodejs.org/download/. You can use curl, wget or your browser to get it:
wget http://nodejs.org/dist/v0.10.34/node-v0.10.34.tar.gz
tar -xvf node-v0.10.34.tar.gz
cd node-v0.10.34
./configure
make
sudo make install
The make might take a while. When done, you should have node and npm installed and working in your /usr/local/bin directory which should be already on your path. You should verify where it lives:
which npm node
I also had to change the permissions to get it to work:
sudo chown -R $USER /usr/local
If it didn't work check your path:
echo $PATH
Note that installing it this way, it will not be managed by apt-get package manager. Cheers!
Recently I had this problem after upgrading node.js (and inevitably npm) to the newest version:
> npm --version
< 2.0.0-alpha-5
Note: I didn't ask for an unstable version, I just got it after brew install npm on OSX.
Downgrading npm fixed the problem for me.
The easiest way to install the stable npm is npm install -g npm but it might not work under some circumstances and downgrade of node.js might be needed then.
The below method worked for me, Kudos to github user : midnightcodr
Make sure You remove any nodejs/npm packages already installed.
sudo apt-get purge nodejs
sudo apt-get purge npm
Now Install Node js using the command below( Thanks to midnightcodr on github)
curl -L https://raw.github.com/midnightcodr/rpi_node_install/master/setup.sh | bash -s 0.10.24
Note that you can invoke node with command node and not nodejs.
Once node is installed , Install npm
sudo apt-get install npm
It could be that the npm registry was down at the time or your connection dropped.
Either way you should upgrade node and npm.
I would recommend using nave to manage your node environments.
https://npmjs.org/package/nave
It allows you to easily install versions and quickly jump between them.
for raspberry pi I found and modified a solution I found
here is what I ran
sudo su -
cd /opt
wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-arm-pi.tar.gz
tar xvzf node-v0.10.28-linux-arm-pi.tar.gz
ln -s node-v0.10.28-linux-arm-pi node
chmod a+rw /opt/node/lib/node_modules
chmod a+rw /opt/node/bin
echo 'PATH=$PATH:/opt/node/bin' > /etc/profile.d/node.sh
the only mod I did was change all 10.25 to 10.28 which was the latest linux-arm-pi at the time
#therefromhere's answer is the best one. However Node versions have moved ever onwards and upwards, and the versioning was complicated by the remerge of io.js. Following the steps in his answer, you will end up with Node version 0.10.25 - not the most recent version.
You should still purge any existing node/npm packages with
sudo apt-get purge nodejs npm
and then go and look at the nodesource deb install page at https://github.com/nodesource/distributions#debinstall.
All Node.js versions are listed on the above page with the Linux commands to install them. And these packages will work on both Debian and Ubuntu.
P.S. If you want to run Node v4.4 or higher on Ubuntu Precise or Debian Wheezy, you should review the information about running on older distros.
P.P.S. If your apt-get is failing, the script will not complete (Google references were failing my apt-get update). You should see messages about the NodeSource signing key being added to your keyring and a final message instructing you to Run 'apt-get install nodejs' to install Node.js.
P.P.P.S. npm is installed with node. Once installed, you can update to the latest npm with sudo npm install npm -g
For people having this issue from a company network which implement a security system that use a mitm for https traffic, you can configure npm to use your company certificate.
npm config set cafile 'path/to/certif-file'
See https://docs.npmjs.com/cli/v9/using-npm/config#cafile
But don't use configs like strict-ssl=false or setting the registry to http://. This is not a secure way of working.

Resources