NodeJS
下载地址
bash
# 20
https://cdn.npmmirror.com/binaries/node/v20.18.0/node-v20.18.0-win-x64.zip
https://cdn.npmmirror.com/binaries/node/v20.18.0/node-v20.18.0-darwin-arm64.tar.gz
https://cdn.npmmirror.com/binaries/node/v20.18.0/node-v20.18.0-linux-x64.tar.xz
# 14
https://cdn.npmmirror.com/binaries/node/v14.21.3/node-v14.21.3-darwin-x64.tar.gz
https://cdn.npmmirror.com/binaries/node/v14.21.3/node-v14.21.2-win-x64.zip
安装
MacOS
Windows
RHEL
创建安装目录,并解压缩
bash
#
mkdir -p /data/app/tools/node/node-cache
mkdir -p /data/app/tools/node/node-store
mkdir -p /data/app/tools/node/node
# 解压缩
tar -Jxvf node-v20.18.0-linux-x64.tar.xz
# 创建软连接
mv ./node-v20.18.0-linux-x64/** /data/app/tools/node/node
#
rm -rf ./node-v20.18.0-linux-x64
添加环境变量
bash
vi /etc/profile.d/node.sh
添加一下内容
bash
export NODE_HOME=/data/app/tools/node/node
export PATH=$PATH:$NODE_HOME/bin:.
启用环境变量
bash
source /etc/profile
检查是否成功安装
bash
node -v
npm -v
bash
npm config set registry=https://registry.npmmirror.com
npm config set cache /data/app/tools/node/node-cache
pnpm config set store-dir /data/app/tools/node/node-store
常用命令
bash
# ========================================================================
# npm
# ========================================================================
# 全局缓存目录
npm set cache /Users/elvea/Tools/node/node-cache
npm set cache /data/app/tools/node/node-cache
npm set cache D:\\Tools\\Node\\node-cache
# 设置镜像
npm config set registry "https://registry.npmmirror.com"
npm config set registry "https://registry.npmjs.org"
# 查看镜像
npm config get registry
# 设置代理
npm config set proxy http://127.0.0.1:7890
npm config set https-proxy http://127.0.0.1:7890
# 取消代理
npm config set proxy null
npm config set https-proxy null
# ========================================================================
# pnpm
# ========================================================================
# 全局缓存目录
pnpm config set store-dir /Users/elvea/Tools/node/pnpm-store
pnpm config set store-dir /data/app/tools/node/pnpm-store
pnpm config set store-dir D:\Tools\Node\pnpm-store
# 镜像
pnpm config set registry https://registry.npmmirror.com
pnpm config get registry
#
npm i -g pnpm --registry=https://registry.npmmirror.com
# ========================================================================
# yarn
# ========================================================================
yarn set version latest
# 全局缓存目录
yarn config set cacheFolder /Users/elvea/Tools/node/yarn-cache
yarn config set cacheFolder /data/app/tools/node/yarn-cache
yarn config set cacheFolder D:\Tools\node\yarn-cache
# 查看全局缓存目录
yarn config get cacheFolder
# 镜像
yarn config set npmRegistryServer https://registry.npmmirror.com
yarn config get npmRegistryServer
# ========================================================================
# CorePack
# ========================================================================
corepack enable
corepack disable
corepack cache clean
#
corepack install --global pnpm@latest
corepack install --global yarn@latest
#
corepack prepare pnpm@latest --activate
corepack prepare yarn@latest --activate
# ========================================================================
# mirrors
# ========================================================================
npm set sharp_binary_host "https://npmmirror.com/mirrors/sharp"
npm set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"
npm set sharp_binary_host "https://npmmirror.com/mirrors/sharp"
npm set sharp_libvips_binary_host "https://npmmirror.com/mirrors/sharp-libvips"
npm set sass_binary_site "https://npmmirror.com/mirrors/node-sass"
npm set fse_binary_host_mirror "https://npmmirror.com/mirrors/fsevents"
npm set profiler_binary_host_mirror "https://npmmirror.com/mirrors/node-inspector"
npm set sqlite3_binary_host_mirror "https://npmmirror.com/mirrors"
npm set sqlite3_binary_site "https://npmmirror.com/mirrors/sqlite3"
npm set puppeteer_download_host "https://npmmirror.com/mirrors/"
npm set chromedriver_cdnurl "https://npmmirror.com/mirrors/chromedriver"
npm set operadriver_cdnurl "https://npmmirror.com/mirrors/operadriver"
npm set phantomjs_cdnurl "https://npmmirror.com/mirrors/phantomjs"
# ========================================================================
# 常用操作
# ========================================================================
# 强制清空缓存
npm cache clean -f
# 不安装开发相关依赖
npm install --production
npmrc
bash
registry=https://registry.npmmirror.com
disturl=https://registry.npmmirror.com/-/binary/node/
#
canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas
sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass
sharp_binary_host=https://registry.npmmirror.com/-/binary/sharp
sharp_libvips_binary_host=https://registry.npmmirror.com/-/binary/sharp-libvips
python_mirror=https://registry.npmmirror.com/-/binary/python/
electron_mirror=https://registry.npmmirror.com/-/binary/electron/
electron_builder_binaries_mirror=https://registry.npmmirror.com/-/binary/electron-builder-binaries/
node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3
better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3
常用工具库
bash
# ====================================================================================
# 强烈推荐安装
# ====================================================================================
npm i -g npm-check-updates
npm i -g gulp-cli
npm i -g @angular/cli
npm i -g @ionic/cli
npm i -g @tarojs/cli
npm i -g cordova
npm i -g cordova-res
npm i -g native-run
npm i -g cross-env
npm i -g typescript
npm i -g prettier
npm i -g eslint
npm i -g rollup
npm i -g ts-node
npm i -g sass
npm i -g lint-staged
npm i -g http-server
npm i -g vite
npm i -g pm2
# ====================================================================================
# 可选安装
# ====================================================================================
npm i -g pnpm
npm i -g yarn
npm i -g node-sass
# ====================================================================================
# 可选安装 - macos
# ios-deploy 可用brew安装
# ====================================================================================
npm i -g ios-sim
npm i -g ios-deploy
NVM
MacOS
bash
# 已安装列表
nvm ls
# 当前版本
nvm current
# 别名
nvm alias
nvm alias default lts/*
nvm alias default 20
nvm alias default 14
# 安装使用最新长期支持版本
nvm install --lts
nvm uninstall --lts
nvm use --lts
# 安装使用指定版本
# 20
nvm run lts/iron --version
nvm install lts/iron
nvm uninstall lts/iron
nvm which lts/iron
nvm use lts/iron
nvm use 20
# 14
nvm run lts/fermium --version
nvm install lts/fermium
nvm uninstall lts/fermium
nvm which lts/fermium
nvm use lts/fermium
nvm use 14
# 本地安装
nvm run system --version
nvm use system
Windows
安装目录
bash
|---D
|---Tools
|---|---Node
|---|---|---node
|---|---|---node-cache
|---|---|---nvm
|---|---|---|---settings.txt
|---|---|---|---v18.18.0
|---|---|---|---v14.21.3
环境变量
bash
NVM_HOME=D:\Tools\Node\nvm
NVM_SYMLINK=D:\Tools\Node\node
配置文件
bash
root: D:\Tools\Node\nvm
path: D:\Tools\Node\node
arch: 64
proxy: none
基本操作
bash
# lts
nvm install lts
nvm use lts
# 18
nvm install 18.12.1
nvm use 18.12.1
# 14
nvm install 14.21.1
nvm use 14.21.1