search

Home  >  Q&A  >  body text

node.js - win10子系统安装node ,如何设置全局

晚上自己的服务器翻墙太慢,更换apt-get源(网易源和搜狐源都试了)后,安装node 都是fail to fetch 404错误。

然后用官网的XZ安装后,在安装目录的bin可以用./node查看版本信息,在$PATH加上node命令的地址(
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Users/hasee/Downloads/node-v6.9.2-linux-x64/bin:/usr/local/src/node-v6.9.2-linux-x64/bin/node
)后全局没有生效

root@DESKTOP-ORQOQ33:/usr/local/src/node-v6.9.2-linux-x64/lib/node_modules/npm# node -v
axconfig: port 1 not active
axconfig: port 2 not active

root@DESKTOP-ORQOQ33:/usr/local/src/node-v6.9.2-linux-x64/lib/node_modules/npm# ./node -v
bash: ./node: No such file or directory
root@DESKTOP-ORQOQ33:/usr/local/src/node-v6.9.2-linux-x64/lib/node_modules/npm#

请问怎么设置全局生效

怪我咯怪我咯2786 days ago662

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-17 15:41:47

    I have never used source code installation, I installed it directly from apt source

    sudo apt update
    sudo apt install nodejs-legacy    //ubuntu源仓库的nodejs,版本大概是4.x.x
    sudo apt install npm    //安装npm,也不是最新版的
    //安装最新版的node和npm
    sudo npm i npm@latest -g    //最新版的npm 4.x.x
    sudo npm i n -g    //n,一个管理node版本的工具,tj大神写的
    sudo n latest    //安装最新版本的node
    
    sudo apt remove nodejs-legacy nodejs    //卸载掉apt方式安装的node
    sudo apt remove npm    //卸载掉apt方式安装的npm

    Next, reopen the terminal and enter node -v which should be the latest version 7.x.x, npm -v which should be the latest version 4.x.x

    reply
    0
  • Cancelreply