KyleBlog.cn 文章 标签 关于
文章 标签 关于

Ubuntu20安装nodejs的3种方法,国内用哪种最方便?

方法1

直接使用Ubuntu自带的官方apt源安装nodejs:

sudo apt-get install -y nodejs

点评:这个方法很简单,但是缺点是版本太旧了,笔者安装后是10.x版本,远远落后于最新版,不支持最新react。

方法2

使用nodejs的私有apt源安装nodejs。

GitHub上有专门的教程:https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions

这里以安装19.x版本的nodejs为例:

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

点评:这个方法稍微麻烦点,支持最新版本。但是,有个缺点:在国内的网络下,速度可能很慢。

方法3

使用snap安装:

sudo snap install node --classic

点评:这个方法是综合最好的。流程简单,速度快,版本也新。

One more thing

无论通过何种方式安装nodejs,最后,记得更新下npm的源,使用国内源,速度快很多:

npm config set registry https://registry.npm.taobao.org

本文为kyleblog.cn原创,转载请注明出处:https://www.kyleblog.cn/posts/ubuntu_nodejs

发布日期:2023-03-08 联系作者