安装Node环境

一、Windows

安装

  1. 安装Node.js:Download | Node.js (nodejs.org)

进入安装软件,无脑进行下一步,需要选择自己的安装路径(最好英文路径 !!!)

出现左图1选择:全选即可

  • node.js runtime:node运行环境
  • orepack manager:npm 包管理
  • Online documentation shortcuts:在线文件快捷方式
  • Add to Path:添加路径
  • corepack manager:核心包管理

中图为安装Node开发工具包等相关包,这里建议不需要安装,使用时候使用Npm进行手动安装即可。出现右图即安装完成。

检查安装情况

分别执行以下命令:

  • node -v:查看版本
  • npm -v:查看npm版本

二、Linux

脚本默认安装系统环境/usr/bin目录下,之后使用npm -g安装其他插件也会安装到/usr/lib/node_modules(需要使用sudo权限)

  1. 使用官方安装脚本安装:nodesource/distributions: NodeSource Node.js Binary Distributions (github.com)
  2. 包管理安装(请自行查阅资料)

安装命令:

Debian

Node.js v18.x

Using Ubuntu

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

Using Debian, as root

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

Node.js v16.x

Using Ubuntu

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

Using Debian, as root

1
2
curl -fsSL https://deb.nodesource.com/setup_16.x | bash - \ &&
apt-get install -y nodejs

Node.js v14.x

Using Ubuntu

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

Using Debian, as root

1
2
curl -fsSL https://deb.nodesource.com/setup_14.x | bash - \ &&
apt-get install -y nodejs

Node.js LTS (v16.x)

Using Ubuntu

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

Using Debian, as root

1
2
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \ &&
apt-get install -y nodejs

Node.js Current (v18.x)

Using Ubuntu

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

Using Debian, as root

1
2
curl -fsSL https://deb.nodesource.com/setup_current.x | bash - \ &&
apt-get install -y nodejs

安装编译工具

use sudo on Ubuntu or run this as root on debian

1
sudo apt-get install -y build-essential

卸载  nodejs

use sudo on Ubuntu or run this as root on debian

1
2
apt-get purge nodejs \ &&
rm -r /etc/apt/sources.list.d/nodesource.list

Centos && Enterprise Linux based distributions

Node.js v18.x

As root

1
curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -

Node.js v16.x

As root

1
curl -fsSL https://rpm.nodesource.com/setup_16.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -

Node.js v14.x

As root

1
curl -fsSL https://rpm.nodesource.com/setup_14.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_14.x | sudo bash -

Node.js LTS (16.x)

As root

1
curl -fsSL https://rpm.nodesource.com/setup_lts.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -

Node.js Current (18.x)

As root

1
curl -fsSL https://rpm.nodesource.com/setup_current.x | bash -

No root privileges

1
curl -fsSL https://rpm.nodesource.com/setup_current.x | sudo bash -

安装编译工具

1
2
yum install gcc-c++ make
# or: yum groupinstall 'Development Tools'

卸载  nodejs

use sudo or run this as root

1
2
3
4
yum remove nodejs \ &&
rm -r /etc/yum.repos.d/nodesource*.repo \ &&
yum clean all
s

检查安装情况

  1. 使用命令:
    • npm -v
    • node -v
  2. 使用脚本(推荐,脚本会自动创建目录执行npm install 检查是否正常):curl -fsSL https://deb.nodesource.com/test | bash -