1. 安装git
2. 卸载之前的node
- sudo rm /usr/local/bin/npm
- sudo rm /usr/local/share/man/man1/node.1
- sudo rm /usr/local/lib/dtrace/node.d
- sudo rm -rf ~/.npm sudo rm -rf ~/.node-gyp
- sudo rm /opt/local/bin/node
- sudo rm /opt/local/include/node
- sudo rm -rf /opt/local/lib/node_modules
3. 安装nvm
-
🔗github 打开hosts文件 sudo vim /private/etc/hosts 然后,在后面拼接以下内容(内容较长,建议复制) github.com 204.232.175.94 gist.github.com 107.21.116.220 help.github.com 207.97.227.252 nodeload.github.com 199.27.76.130 raw.github.com 107.22.3.110 status.github.com 204.232.175.78 training.github.com 207.97.227.243 www.github.com
-
命令行安装选择其中一个就可以,我选择第一个安装成功,需要关闭命令行,输入nvm -v
export NVM_SOURCE=https://gitlab.com/mirrorx/nvm.git curl -o- https://gitlab.com/mirrorx/nvm/-/raw/master/install.sh | bash export NVM_SOURCE=https://gitlab.com/mirrorx/nvm.git wget -qO- https://gitlab.com/mirrorx/nvm/-/raw/master/install.sh | bash
5. 安装node
- nvm install 8.0.0 安装指定版本号的
- node nvm use 8.0 [当前目录]使用8.0.x可用的最新版本
- nvm run 6.10.3 app.js 当前目录使用6.10.3版本的node运行app.js
- nvm exec 4.8.3 node app.js 使用4.8.3版本的node运行制定路径的app.js
- nvm alias default 8.1.0 在shell中配置默认node版本
- nvm alias default node 在shell中配置默认使用最新版本的node
- nvm install node 安装最新版本的node
- nvm use node 当前目录使用最新版本的node
- nvm install --lts 安装最新稳定版本的node
- nvm use --lts 当前目录使用最新稳定版本的node nvm set-[colors]cgYmW 设置文本颜色为cyan, green, bold yellow, magenta, and white
- nvm list 查看当前已安装node列
一些项目报错
问题描述:
在初始化项目的时候出现这个报错
npm ERR! code ENOLOCAL
npm ERR! Could not install from "" as it does not contain a package.json file.
解决方案
npm install -g npm