ununtu安装node.js_LTS

ubuntu 安装 LTS 版本 Node.js

ubuntu 安装 LTS 版本 Node.js

今天在服务器上安装 Node.js ,用了下面的命令:

1
2
$ sudo apt-get update
$ sudo apt-get install nodejs

结果看了下安装的版本居然是 10.x 的,现在 LTS 版本都是 14.x 了,怎么才能安装 LTS 版本呢?网上搜了下可以在安装的时候指定版本:

1
$ sudo apt install nodejs=14.18.1

但是执行却提示找不到版本:

Version ‘14.18.1’ for ‘nodejs’ was not found

又到网上查了下,原来是要添加源之后安装:

1
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

这里添加的是 14.x 的版本,如果安装其他版本,只需要修改添加源地址的数字即可

再次尝试安装:

1
$ sudo apt-get install -y nodejs

安装成功,查看版本号:

1
2
$ node -v # v14.18.1
$ npm -v # 6.14.15
Author

Daniel Niu

Posted on

2024-04-13

Updated on

2024-06-26

Licensed under

Comments