使用nvm管理node版本

nvm管理node版本

安装

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh|bash

配置环境

1
2
3
4
5
6
7
[Wed Jul 24 talen@tp-arch-tianfei ~]$ vim  ~/.bashrc
# nvm
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node
#source /usr/share/nvm/init-nvm.sh
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

查看lts版本

1
2
3
4
5
6
[Wed Jul 24 talen@tp-arch-tianfei ~]$ nvm ls-remote --lts
v4.2.0 (LTS: Argon)
...
v10.15.2 (LTS: Dubnium)
-> v10.15.3 (LTS: Dubnium)
v10.16.0 (Latest LTS: Dubnium)

安装指定版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[Wed Jul 24 talen@tp-arch-tianfei ~]$ nvm install v10.16.0
Downloading and installing node v10.16.0...
Downloading https://npm.taobao.org/mirrors/node/v10.16.0/node-v10.16.0-linux-x64.tar.xz...
################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.16.0 (npm v6.9.0)
[Wed Jul 24 talen@tp-arch-tianfei ~]$ node -v
v10.16.0
[Wed Jul 24 talen@tp-arch-tianfei ~]$ nvm ls
v10.15.3
-> v10.16.0
v12.2.0
system
default -> lts/* (-> v10.16.0)
node -> stable (-> v12.2.0) (default)
stable -> 12.2 (-> v12.2.0) (default)
iojs -> N/A (default)
lts/* -> lts/dubnium (-> v10.16.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.0 (-> N/A)
lts/dubnium -> v10.16.0

切换版本

1
2
3
4
5
6
7
8
9
10
11
[Wed Jul 24 talen@tp-arch-tianfei ~]$ nvm use v10.16.0
Now using node v10.16.0 (npm v6.9.0)
[Wed Jul 24 talen@tp-arch-tianfei ~]$ nvm current
v10.16.0
[Wed Jul 24 talen@tp-arch-tianfei ~]$ which npm
/home/talen/.nvm/versions/node/v10.16.0/bin/npm
[Wed Jul 24 talen@tp-arch-tianfei ~]$ which node
/home/talen/.nvm/versions/node/v10.16.0/bin/node

[Thu Jul 25 talen@tp-arch-tianfei github]$ nvm use lts/*
Now using node v10.16.0 (npm v6.9.0)
坚持原创技术分享,您的支持将鼓励我继续创作!