2015-09-03 185 views
2

我必须安装节点和npm。在安装之前,我做了一些搜索以安装这些东西的最佳方式。我发现是:安装节点和npm的问题

  1. 安装nvm
  2. 使用nvm
  3. 设置nvm alias default使得node将可通过默认安装node
  4. 在安装node时,您还将获得npm
  5. 将全局模块目录更改为HOME中的某个路径,以便在安装全局作用域使用npm的程序包时,不必使用sudo。
  6. 再次使用npm作为全局模块安装npm
  7. 添加新的全局模块目录的bin我们$PATH环境变量

但这样做npm不工作后。它给予以下错误:

$ npm install -g yo 

> [email protected] postinstall /Users/aapa/.node_modules_global/lib/node_modules/yo/node_modules/cross-spawn/node_modules/spawn-sync 
> node postinstall 

/Users/aapa/.node_modules_global/bin/yo -> /Users/aapa/.node_modules_global/lib/node_modules/yo/lib/cli.js 

> [email protected] postinstall /Users/aapa/.node_modules_global/lib/node_modules/yo 
> yodoctor 

sh: yodoctor: command not found 
npm ERR! Darwin 14.3.0 
npm ERR! argv "node" "/Users/aapa/.node_modules_global/bin/npm" "install" "-g" "yo" 
npm ERR! node v0.12.7 
npm ERR! npm v2.14.1 
npm ERR! file sh 
npm ERR! code ELIFECYCLE 
npm ERR! errno ENOENT 
npm ERR! syscall spawn 

npm ERR! [email protected] postinstall: `yodoctor` 
npm ERR! spawn ENOENT 
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script 'yodoctor'. 
npm ERR! This is most likely a problem with the yo package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  yodoctor 
npm ERR! You can get their info via: 
npm ERR!  npm owner ls yo 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /Users/aapa/npm-debug.log 

这里是所有我遇到的实际命令:

#1. Install nvm 
$curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | bash 

#2. Install node using nvm 
$nvm install node 
# This will install the latest stable version of node. Here `node` is an alias to stable 
#node -> stable (-> v0.12.7) (default) 
#stable -> 0.12 (-> v0.12.7) (default) 

#3. Set the nvm alias default so that the node will be available by default. 
$nvm alias default node 

#4. You will also get npm while installing node. 
$ which npm 
/Users/aapa/.nvm/versions/node/v0.12.7/bin/npm 

#5. Change the global modules directory to some path inside your HOME so that while installing global scoped packages using npm you don't have to use sudo. 
$ npm config get prefix 
/Users/aapa/.nvm/versions/node/v0.12.7 
$ cd && mkdir .node_modules_global 
$ npm config set prefix=$HOME/.node_modules_global 
$ npm config get prefix 
/Users/aapa/.node_modules_global 
$ cat .npmrc 
prefix=/Users/aapa/.node_modules_global 

#6. Install npm again using npm as a global module. 
$ npm install npm --global 
/Users/aapa/.node_modules_global/bin/npm -> /Users/aapa/.node_modules_global/lib/node_modules/npm/bin/npm-cli.js 
[email protected] /Users/aapa/.node_modules_global/lib/node_modules/npm 

#7. Add new global module directory's `bin` to our `$PATH` environment variable 
$ echo -e '\n\n#adding npm global module location to path\nexport PATH="$HOME/.node_modules_global/bin:$PATH"' >> ~/.bash_profile 
$ source ~/.bash_profile 

# check 
$ which npm 
/Users/aapa/.node_modules_global/bin/npm 

也有对网络的一些其他相关资源:

  1. SO- NPM permission error while installing - 建议在这里的答案使用我试图避免的sudo
  2. Yeoman issues - can not install yeoman on my mac running OS X Yosemite 10.10.1 - 我想我已经完成了所有的解决方案,除了这里的解决方案使用了.bashrc和我已经使用了.bash_profile

我不知道我在哪里做错了。有任何想法吗?

回答

0

我认为最好和最简单的方法是从网站上下载节点nodejs.org并安装它。

后打开CMD,进入下载从那里的NodeJS文件夹并键入

npm install package-name 

,如果你想在全球范围内安装它然后使用-g像

npm install package-name -g 
0

最简单的解决方法是简单地不做步骤5,6和7.

缺点是你必须分别安装你使用的每个版本的节点的全局变量,但它听起来像你不是' t经常更新版本。