简体   繁体   English

npm全局安装ganache-cli失败(由于sudo / permissions)

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

I have npm version 6.5.0 and node v10.10.0. 我有npm版本6.5.0和节点v10.10.0。 There have been no previous issues with npm global installs. npm全局安装以前没有问题。

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. 基本问题是,使用npm全局安装软件包npm它们链接到/usr/local/下的目录,该目录通常由root用户拥有。

Node Version Manager (nvm) is one way to circumvent such tricky permissions issues. 节点版本管理器(nvm)是避免此类棘手的权限问题的一种方法。 It allows globally installed packages to be linked into directories in your home folder under ~/.nvm/versions/node/<version> 它允许将全局安装的软件包链接到主文件夹中的~/.nvm/versions/node/<version>

Using my package manager, I removed node and related software such as npm . 使用软件包管理器,删除了node和相关软件,例如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 . 我使用find /usr/local/ -name 'node_modules'来搜索/usr/local/以查找以前在npm全局安装的软件包的所有痕迹。 Delete them all. 全部删除。

Then I installed nvm using the latest install script from https://github.com/creationix/nvm 然后我使用来自https://github.com/creationix/nvm的最新安装脚本安装了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. 然后,我必须将nvm链接到我的环境路径中。 In my case, this meant manually editing my .bashrc profile to include this: 就我而言,这意味着手动编辑.bashrc配置文件以包括以下内容:

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获取最新的LTS版本的node。

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! 现在,可以在没有sudo情况下安装全局安装的软件包,因为它们存放在~/.nvm/versions/node/v10.14.2/并且一切正常!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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