1、把nvm远程镜像克隆到指定目录
git clone https://gitee.com/mirrors/nvm
drc@iZwz91oq31508figapkas0Z:~/qiang/tools$ git clone https://gitee.com/mirrors/nvm
fatal: destination path 'nvm' already exists and is not an empty directory.
drc@iZwz91oq31508figapkas0Z:~/qiang/tools$ ls
nvm
drc@iZwz91oq31508figapkas0Z:~/qiang/tools$ cd nvm
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ ls
bash_completion CONTRIBUTING.md GOVERNANCE.md LICENSE.md nvm-exec package.json README.md ROADMAP.md update_test_mocks.sh
CODE_OF_CONDUCT.md Dockerfile install.sh Makefile nvm.sh PROJECT_CHARTER.md rename_test.sh test
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$
2、安装nvm
进入nvm目录内执行安装命令,
bash install.sh
根据执行安装命令后的提示继续执行提示内容:
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ sudo bash install.sh
=> nvm is already installed in /root/.nvm, trying to update using git
=> => Compressing and cleaning up git repository
=> nvm source string already in /root/.bashrc
=> bash_completion source string already in /root/.bashrc
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:
/usr/local/lib
├── corepack@0.10.0
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` Nodes), you can remove them from the system Node as follows:
$ nvm use system
$ npm uninstall -g a_module
=> Close and reopen your terminal to start using nvm or run the following to use it now:
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
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ export NVM_DIR="$HOME/.nvm"
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ nvm --version
0.39.1
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$
通过nvm --version可以看到安装成功。
3、使用nvm安装node16.13.1并使用该版本:
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ nvm ls
-> system
iojs -> N/A (default)
node -> stable (-> N/A) (default)
unstable -> N/A (default)
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ nvm install 16.13.1
Downloading and installing node v16.13.1...
Downloading https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-x64.tar.xz...
################################################################################################################################################################################################################ 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.13.1 (npm v8.1.2)
Creating default alias: default -> 16.13.1 (-> v16.13.1)
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ nvm ls
-> v16.13.1
system
default -> 16.13.1 (-> v16.13.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.13.1) (default)
stable -> 16.13 (-> v16.13.1) (default)
lts/* -> lts/gallium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.19.2 (-> N/A)
lts/gallium -> v16.15.0 (-> N/A)
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ nvm use 16.13.1
Now using node v16.13.1 (npm v8.1.2)
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$ node -v
v16.13.1
drc@iZwz91oq31508figapkas0Z:~/qiang/tools/nvm$
注意该方法只有在nvm中执行对应命令后才起作用,退出终端再切换版本需要重新执行对应命令。