【node】之nvm的使用

nvm是什么?

你可以把nvm理解为python里面的virtualenv
如果想在同一台机器,同时安装多个版本的node.js,就需要用到版本管理工具nvm。

http://javascript.ruanyifeng.com/nodejs/basic.html#toc6

安装nvm

  1. 使用git克隆下来
    cd ~/ from anywhere then git clone https://github.com/nvm-sh/nvm.git .nvm
  2. 切换到指定分支
    cd ~/.nvm and check out the latest version with git checkout v0.34.0
  3. 激活nvm
    activate nvm by sourcing it from your shell: . nvm.sh
  4. 在.bash_profile中添加指定内容
    Now add these lines to your ~/.bashrc, ~/.profile, or ~/.zshrc file to have it automatically sourced upon login: (you may have to add to more than one of the above files)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

使用

下载指定版本node
nvm install v10.15.3
使用指定版本node
nvm use v10.15.3

查看版本号

node -v
v10.15.3
npm -v
6.4.1
which node
~/.nvm/versions/node/v10.15.3/bin/node

which npm
~/.nvm/versions/node/v10.15.3/bin/npm

posted @ 2022-03-06 10:38  叶常落  阅读(85)  评论(0编辑  收藏  举报