简体   繁体   English

如何在 Ubuntu 上安装最新版本的 Nodejs?

[英]how to install a latest version of Nodejs on Ubuntu?

I start using ubuntu (22.04.1) recently.我最近开始使用 ubuntu (22.04.1)。 I want to install nodejs latest version (currently v18.12.1 LTS).我想安装 nodejs 最新版本(当前为 v18.12.1 LTS)。 But my node --version showing version v12.22.9.但我的node --version显示版本 v12.22.9。

First I install node using sudo apt-get install nodejs .首先,我使用sudo apt-get install nodejs安装节点。 Then I re-install my node but before re-install I update my system using sudo apt update && sudo apt upgrade .然后我重新安装我的节点,但在重新安装之前我使用sudo apt update && sudo apt upgrade更新我的系统。 But i keep getting same result.但我一直得到相同的结果。 node version v12.22.9.节点版本 v12.22.9。

Don't use the distribution's default, Ubuntu is extremely conservative with bumping versions of things like Node, so instead go with Node's repository.不要使用发行版的默认设置,Ubuntu 对 Node 之类的更新版本非常保守,因此请使用 Node 的存储库。

The current location is documented in the installer instructions : 安装程序说明中记录了当前位置:

curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

Where the setup_ scripts usually do a good job of getting everything properly sorted. setup_脚本通常可以很好地正确排序所有内容。

For the 18 LTS version:对于 18 LTS 版本:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

I would use nvm - Node Version Manager, see https://github.com/nvm-sh/nvm#install--update-script我会使用 nvm - 节点版本管理器,请参阅https://github.com/nvm-sh/nvm#install--update-script

This has a couple of advantages: you don't change the system's node version (which might be used elsewhere) and you may select a distinct (older or newer) version of node accompanied by appropriate installations of npm, yarn, aso It's simple to install "global" packages just locally (kind of oxymoron...) for your user.这有几个优点:您不需要更改系统的节点版本(可能在其他地方使用)并且您可以选择一个不同的(旧的或更新的)节点版本,同时适当安装 npm、yarn 和 aso为您的用户在本地安装“全局”包(有点矛盾......)。 You don't need root permission for these.您不需要这些权限。

1-Install CURL if you don't have: 1-如果没有安装 CURL:

sudo apt-get install curl sudo apt-get 安装卷曲

2-Run the following command to add the PPA to the Ubuntu system: 2-运行以下命令将PPA添加到Ubuntu系统:

curl -fsSL https://deb.nodesource.com/setup_16.x |卷曲-fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&\须藤 -E bash - &&\

3-After successfully adding the PPA to the system, execute the command below to install Node on Ubuntu: 3-成功将PPA添加到系统后,执行以下命令在Ubuntu上安装Node:

sudo apt-get install nodejs sudo apt-get 安装 nodejs

4-check the version number of the installed software for node: 4-查看node安装软件的版本号:

node -v节点-v

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM