nvm切换node版本-jenkins上编译
在jenkins上前端打包时经常需要切换不同的node版本,之前是下载不同版本的安装包在服务器上
为切换快捷方便使用nvm
jenkins上流水线修改
source ~/.nvm/nvm.sh
export PATH="/root/.nvm/versions/node/'${NPM_VERSION}'/bin:$PATH"
nvm install '${NPM_VERSION}'
nvm use '${NPM_VERSION}'
npm install -g yarn
nrm use taobao
yarn install
yarn run build
nvm常用命令
# 安装 NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash# 更新 NVM
nvm upgrade# 安装指定 Node.js 版本
nvm install 18.20.8# 安装最新 LTS 版本
nvm install --lts# 列出所有远程可用版本
nvm ls-remote# 列出本地已安装版本
nvm ls# 使用特定版本
nvm use 16.20.2# 设置默认版本
nvm alias default 18.20.8# 在当前 shell 运行特定版本的 Node
nvm run 14.21.3 app.js# 切换到最新安装的版本
nvm use node# 卸载指定版本
nvm uninstall 14.21.3# 强制卸载(即使正在使用)
nvm uninstall --force 14.21.3# 查看当前使用版本
nvm current# 为项目创建 .nvmrc 文件
echo "18.20.8" > .nvmrc
nvm use# 检查哪些版本已过时
nvm ls-remote --lts | grep -v $(nvm ls --no-colors | grep '^->' | cut -d' ' -f2)
nrm常用命令
# 全局安装 NRM
npm install -g nrm# 列出所有可用镜像源
nrm ls# 测试各镜像源速度
nrm test# 切换镜像源
nrm use taobao# 添加自定义镜像源
nrm add company http://npm.company.com/# 删除镜像源
nrm del company# 查看当前使用源
nrm current# 查看源详细信息
nrm inspect taobao# 测试特定源响应时间
nrm test npm taobao