如何在 Ubuntu 20.04 上将 Node.js 更新为长期支持版本?

Mik*_*ike 9 nodejs

我对 Ubuntu 很陌生。我可以将 Node.js 安装到最新版本 14.7.0,但我正在使用的程序 (Jhipster) 告诉我我需要安装长期支持(LTS,当前为 12.18.3)并且不知道如何去做吧。

有node-v12.18.3-linux-x64.tar.xz文件,在windows下看起来像zip文件,但是不知道怎么安装(文件管理器打开的时候不会自己安装)

我试图谷歌关于如何选择版本,但我可以找到如何去做。麻烦各位大侠解释一下。谢谢。

Ahm*_*raa 25

将 nodejs 更新到 14.x

 sudo apt update
 curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
 sudo apt install -y nodejs
 node -v
Run Code Online (Sandbox Code Playgroud)
  • 你应该看到:v14.15.0


小智 11

2022 年更新

自从这个问题发布后,版本 16 成为最新的 LTS 版本。因此,Ahmed Boutaraa 的答案对于问题的版本 14 部分来说是正确的,但遇到这个问题的人可能正在寻求最新的 LTS。如果您遵循这些说明,您将陷入版本 14。

幸运的是,NodeSource 还提供了一个安装脚本,用于安装当前的 LTS 而不是特定版本。这应该会让这个答案更加面向未来。您还可以直接从来源获得相同的信息。

如何安装最新的 LTS 版本

这组说明将安装最新的 LTS 版本。当新版本发布时,您可能需要再次运行这些说明才能提取新版本的新安装脚本。

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

# As root
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)

如何安装最新的非 LTS 版本

这组说明将安装最新的非 LTS 版本。当新版本发布时,您可能需要再次运行这些说明才能提取新版本的新安装脚本。

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs

# As root
curl -fsSL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)

如何锁定到 v17(目前最新)

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
sudo apt-get install -y nodejs

# As root
curl -fsSL https://deb.nodesource.com/setup_17.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)

如何锁定到 v16(当前 LST)

# As a user with sudo
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

# As root
curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
apt-get install -y nodejs
Run Code Online (Sandbox Code Playgroud)


小智 9

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ~/.bashrc
nvm list-remote
nvm install v14.17.6
Run Code Online (Sandbox Code Playgroud)

在最后一个命令中,从上一个命令中显示的列表中选择要安装的版本。