简体   繁体   中英

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM