nodejs环境搭建

36 阅读1分钟

使用nvm管理nodejs版本,操作如下:

# 1. nvm 命令工具下载
### 1.1 普通方式克隆
git clone https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
### 1.2 使用代理的方式克隆
git clone -c http.proxy="127.0.0.1:7890" https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`

# 2. 配置 nvm 命令
echo ". ~/.nvm/nvm.sh" >> /etc/profile  
source /etc/profile

# 3. 安装 nodejs 当前长期稳定版
nvm install v10.14.2

# 4. 测试
node -v

# 5. 通过 nvm 查看当前使用的 nodejs 版本
nvm current

# 6. 切换版本
nvm use [版本]

# 7. npm 切换为国内镜像
npm config set registry https://registry.npm.taobao.org

# 8. 查看是否切换成功
npm config get registry