s-blog

Ubuntu 安装 Node.js

ssssmy · 2026-06-05 · 1 min · Ubuntu

一、安装

sudo apt-get install nodejs
sudo apt-get install npm

二、升级 / 切换版本(n)

sudo npm install npm -g
npm install -g n
n latest    # 升级到最新版
n stable    # 升级到最新稳定版

三、npm 镜像替换为淘宝镜像

# 查看当前镜像地址
npm get registry
# 设为淘宝镜像
npm config set registry https://registry.npmmirror.com/
# 换回官方
npm config set registry https://registry.npmjs.org/

四、选装 cnpm

npm install cnpm -g --registry=https://registry.npmmirror.com

五、卸载

sudo npm uninstall npm -g
sudo apt-get remove nodejs

原文链接:https://www.ssssmy.com/notes/ubuntu-an-zhuang-nodejs