Update Node Using a Package Manager nodesource

How to Update Node.js to Latest Version (Linux, Ubuntu, OSX, Others) - HostingAdvice.com https://www.hostingadvice.com/how-to/update-node-js-latest-version/

How do I update Node.js? - Stack Overflow https://stackoverflow.com/questions/8191459/how-do-i-update-node-js

  1. sudo npm cache clean -f
    
  2. Install a little helper called 'n'

    sudo npm install -g n
    
  3. Install latest stable Node.js version

    sudo n stable
    

Alternatively pick a specific version and install like this:

sudo n 0.8.20





如何在 Ubuntu 20.04 上安装 Node.js 和 npm - ITCoder https://www.itcoder.tech/posts/how-to-install-node-js-on-ubuntu-20.04/?spm=a2c4e.10696291.0.0.353b19a4H6AYZg

二、 从 NodeSource 中安装 Node.js 和 npm

NodeSource 是一个公司,聚焦于提供企业级的 Node 支持。它维护了一个 APT 软件源,其中包含了很多 Node.js 版本。如果你的应用需要指定版本的Node.js 版本,使用这个软件源。

在写作的时候,NodeSource 软件源提供了以下版本:

  • v14.x - 最新稳定版
  • v13.x
  • v12.x - 最新长期版本
  • v10.x - 前一个长期版本

我们将会安装 Node.js 版本 14.x:

01.以 sudo 用户身份运行下面的命令,下载并执行 NodeSource 安装脚本:

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

这个脚本将会添加 NodeSource 的签名 key 到你的系统,创建一个 apt 源文件,安装必备的软件包,并且刷新 apt 缓存。

如果你需要另外的 Node.js 版本,例如12.x,将setup_14.x修改为setup_12.x

02.一旦 NodeSource 源被启用,安装 Node.js 和 npm:

sudo apt install nodejs

nodejs 软件包同时包含nodenpm二进制包。

03.验证 Node.js 和 npm 是否正确安装。打印它们的版本号:

node --version

输出:

v14.2.0
npm --version

输出:

6.14.4

想要从 npm 编译本地扩展,你需要安装开发工具:

sudo apt install build-essential






Nodesource 镜像使用帮助

Nodesource 为 debian, ubuntu, fedora, RHEL 等发行版提供预编译的 nodejs 和 npm 等软件包。

debian/ubuntu 使用方法

运行

curl -sL https://deb.nodesource.com/setup | sudo bash - # or
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash - # or
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -

编辑 /etc/apt/sources.list.d/nodesource.list,把 https://deb.nodesource.com/node/ 替换为 https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb/ 即可。

如果是 https://deb.nodesource.com/node_10.x/ ,则改为 https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_10.x/ 。

 
原文地址:https://www.cnblogs.com/rsapaper/p/13083646.html