Linux安装Nodejs

NodeSource 安装Node.js

https://github.com/nodesource/distributions

目前centos7 支持 node16

安装后 包括了 nodejs 与 npm

npm 换源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
临时使用
npm --registry  https://registry.npm.taobao.org install express

持久使用
npm config set registry  https://registry.npm.taobao.org

通过cnpm
npm install -g cnpm --registry= https://registry.npm.taobao.org

使用官方镜像
npm config set registry  https://registry.npmjs.org/

查看npm源地址
npm config get registry

npm 手动安装

  1. 官网下载 进入Node最新版下载 <https://nodejs.org/en/download/current/
1
wget https://nodejs.org/dist/v18.16.0/node-v18.16.0-linux-x64.tar.xz
  1. 解压
1
tar -xvf node-v18.16.0-linux-x64.tar.xz
  1. 配置
1
2
3
# node
export NODEROOT=/usr/local/lib/node18.15
export PATH=$NODEROOT/bin:$PATH