Reputation: 292
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
Upvotes: 0
Views: 1327
Reputation: 292
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!
Upvotes: 1