Linux安装Node.js

安装 fnm:

curl -o- https://fnm.vercel.app/install | bash
source ~/.bashrc

安装 Node.js 24,并设置为默认版本:

fnm install 24
fnm use 24
fnm default 24

确认版本:

node -v
npm -v

查看已经安装和当前使用的版本:

fnm list
fnm current

项目目录中可以创建.node-version文件:

24

进入项目目录后执行fnm use即可切换到对应版本。

Windows安装ZIP便携版

Node.js官方下载页面下载win-x64.zip,解压到:

D:\Portable Software\Node

在当前用户的Path中添加:

D:\Portable Software\Node

重新打开终端并确认版本:

where node
node -v
npm -v

因为 ZIP 便携版不会通过安装程序另外设置 npm 的prefix,所以 npm 全局目录默认就是 Node 解压目录D:\Portable Software\Node,全局包保存在其中的node_modules下。

如需配置 npmmirror,新建文件:

D:\Portable Software\Node\node_modules\npm\npmrc

写入:

registry=https://registry.npmmirror.com/

npm常用命令

设置仓库:

npm config set registry https://registry.npmmirror.com/

设置代理:

npm config set proxy http://127.0.0.1:10808
npm config set https-proxy http://127.0.0.1:10808

只在本次安装时使用代理:

npm install package-name --proxy=socks5://127.0.0.1:10808

查看配置:

npm config list
npm config get registry
npm config get proxy
npm config get https-proxy

清除代理:

npm config delete proxy
npm config delete https-proxy