CentOS 7.6下安装 NVM 管理不同版本的 Node.js

nvm全称Node Version Manager是 Nodejs 版本管理器,它让我们能方便的对 Node.js 的版本进行切换。 nvm 的官方版本只支持 Linux 和 MacWindows 用户可以用 nvm-windows。详情请点击官方说明。

安装NVM

资料得出,要使用 curl 或 wget 来安装nvm(版本可以选用官网最新版):

[linuxidc@localhost www.linuxidc.com]$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash

输出示例如下:

  % Total    % Received % Xferd  Average Speed  Time    Time    Time  Current
                                Dload  Upload  Total  Spent    Left  Speed
100 13527  100 13527    0    0  22484      0 –:–:– –:–:– –:–:– 22545
=> Downloading nvm from git to ‘/home/linuxidc/.nvm’
=> 正克隆到 ‘/home/linuxidc/.nvm’…
remote: Enumerating objects: 286, done.
remote: Counting objects: 100% (286/286), done.
remote: Compressing objects: 100% (256/256), done.
remote: Total 286 (delta 34), reused 93 (delta 17), pack-reused 0
接收对象中: 100% (286/286), 146.90 KiB | 0 bytes/s, done.
处理 delta 中: 100% (34/34), done.
=> Compressing and cleaning up git repository

=> Appending nvm source string to /home/linuxidc/.bashrc
=> Appending bash_completion source string to /home/linuxidc/.bashrc
=> 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

CentOS 7.6下安装 NVM 管理不同版本的 Node.js

或:

[linuxidc@localhost www.linuxidc.com]$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash

注意:安装完了,重新打开终端 Terminal来重启会话

安装 Node.js

新版

1、安装最新版 Node.js 命令

[linuxidc@localhost www.linuxidc.com]$ nvm install node
Downloading and installing node v12.11.1…
Downloading https://nodejs.org/dist/v12.11.1/node-v12.11.1-linux-x64.tar.xz…
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.11.1 (npm v6.11.3)
Creating default alias: default -> node (-> v12.11.1)

CentOS 7.6下安装 NVM 管理不同版本的 Node.js

2.查看安装效果,命令:

[linuxidc@localhost www.linuxidc.com]$ nvm use node

输出如下:

Now using node v12.11.1 (npm v6.11.3)

CentOS 7.6下安装 NVM 管理不同版本的 Node.js

稳定版(LTS)

1、安装 LTS 版,命令:nvm install –lts

[linuxidc@localhost www.linuxidc.com]$ nvm install –lts
Installing latest LTS version.
Downloading and installing node v10.16.3…
Downloading https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-x64.tar.xz…
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.16.3 (npm v6.9.0)

CentOS 7.6下安装 NVM 管理不同版本的 Node.js

2、查看安装效果,命令:
[linuxidc@localhost www.linuxidc.com]$ nvm list

输出如下:

      v10.16.3
->    v12.11.1
default -> node (-> v12.11.1)
node -> stable (-> v12.11.1) (default)
stable -> 12.11 (-> v12.11.1) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/dubnium (-> v10.16.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.1 (-> N/A)
lts/dubnium -> v10.16.3

CentOS 7.6下安装 NVM 管理不同版本的 Node.js

切换版本

从上面的安装列表上已经可以看到,我们安装了一个最新版,一个稳定版。分别是:v12.11.1 和 v10.16.3,我们要如何切换不同版本呢?
1.切换到 v12.11.1,命令:

[linuxidc@localhost www.linuxidc.com]$ nvm use v12.11.1

显示:

Now using node v12.11.1 (npm v6.11.3)

2.切换到 v10.16.3,命令:

[linuxidc@localhost www.linuxidc.com]$ nvm use v10.16.3

显示:

Now using node v10.16.3 (npm v6.9.0)

CentOS 7.6下安装 NVM 管理不同版本的 Node.js

到这里,我们基本会使用 nvm 了,想用什么版本就可以自由切换。 但如果想玩得更爽一点,就要学习如下一技巧

使用别名

你肯定也想到,每次输入v10.16.3 好麻烦。并且时间长了,不一定记得住后面是16.3,还是18.3的版本号。

1、设定 LTS 版别名,命令:

[linuxidc@localhost www.linuxidc.com]$ nvm alias 10 v10.16.3

显示

10 -> v10.16.3

2、设定最新版别名,命令:

[linuxidc@localhost www.linuxidc.com]$ nvm alias 12 v12.11.1

显示

12 -> v12.11.1

CentOS 7.6下安装 NVM 管理不同版本的 Node.js

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

栗子博客 软件 CentOS 7.6下安装 NVM 管理不同版本的 Node.js https://www.lizi.tw/soft/16656.html

常见问题
  • 1、杰齐1.7仅适用于PHP5.2 2、需Zend支持 3、尽量使用宝塔面板 4、尽量使用Windows 系统,关关对Linux支持不太友好。
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

CentOS 7.6下安装 NVM 管理不同版本的 Node.js-海报

分享本文封面