node npm安装与升级

[Linux]

一、安装 nodejs

方法一:源码编译

sudo git clone https://github.com/nodejs/node.git
sudo chmod -R 755 node
cd node
sudo ./configure
sudo make
sudo make install

方法二:包管理器安装

ubuntu为例,其他看这里-》https://github.com/nodesource/distributions/blob/master/README.md

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

二、升级更新 nodejs

1)安装 nodejs 的版本管理器 n

sudo npm install -g n

注:如果你还未安装npm,请先安装npm(可能会报缺少依赖,缺啥就补啥,补完之后再安装 npm)

2)使用 n 切换(更新) nodejs 版本

# 最新版本
n lastest
# 稳定版本
n stable
# 安装指定版本
n 10.12.0

注:更新完要重启一下系统 

[Windows]

一、安装 nodejs

前往nodejs官网-》https://nodejs.org/en/download/

下载适合自己的最新的安装包(.msi),直接双击安装即可

二、更新 nodejs

windows系统没办法使用 n 来更新 nodejs 版本,要更新 nodejs 的话,重新下载 nodejs,覆盖安装即可

如果不知道nodejs的安装目录,可以使用以下命令来查看

npm config ls


原文地址:https://www.cnblogs.com/tujia/p/12176052.html