Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 安装node和npm中的问题_Node.js_Macos_Npm_Yeoman_Nvm - Fatal编程技术网

Node.js 安装node和npm中的问题

Node.js 安装node和npm中的问题,node.js,macos,npm,yeoman,nvm,Node.js,Macos,Npm,Yeoman,Nvm,我必须安装node和npm。在安装之前,我搜索了一下安装这些东西的最佳方法。我发现的是: 安装nvm 使用nvm安装节点 设置nvm别名默认值,使节点默认可用 安装节点时,您还将获得npm 将全局模块目录更改为HOME中的某个路径,以便在使用npm安装全局范围的软件包时,不必使用sudo 使用npm作为全局模块再次安装npm 将新的全局模块目录的bin添加到我们的$PATH环境变量中 但在执行此操作后,npm不起作用。它给出了以下错误: $ npm install -g yo > spa

我必须安装node和npm。在安装之前,我搜索了一下安装这些东西的最佳方法。我发现的是:

  • 安装
    nvm
  • 使用
    nvm安装
    节点
  • 设置
    nvm别名默认值
    ,使
    节点默认可用
  • 安装
    节点时,您还将获得
    npm
  • 将全局模块目录更改为
    HOME
    中的某个路径,以便在使用
    npm
    安装全局范围的软件包时,不必使用sudo
  • 使用
    npm
    作为全局模块再次安装
    npm
  • 将新的全局模块目录的
    bin
    添加到我们的
    $PATH
    环境变量中
  • 但在执行此操作后,
    npm
    不起作用。它给出了以下错误:

    $ npm install -g yo
    
    > spawn-sync@1.0.13 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
    
    > yo@1.4.7 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! yo@1.4.7 postinstall: `yodoctor`
    npm ERR! spawn ENOENT
    npm ERR!
    npm ERR! Failed at the yo@1.4.7 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
    npm@2.14.1 /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
    
    网站上还有一些其他相关资源:

  • -这里的答案建议使用我试图避免的
    sudo
  • -我想我已经按照这里的解决方案做了所有事情,除了这里的解决方案使用了
    .bashrc
    ,我还使用了
    .bash\u profile

  • 我不知道我哪里做错了。有什么想法吗?

    我认为最好、最简单的方法就是从nodejs.org网站下载node并安装它

    然后打开cmd,从那里转到下载nodejs文件夹并键入

    npm install package-name
    
    如果您想在全局范围内安装它,那么使用-g like

    npm install package-name -g
    

    最简单的解决方案是不执行步骤5、6和7

    缺点是您必须为正在使用的每个版本的节点分别安装globals,但听起来您并不是经常切换版本

    相关:。