Node.js 速查

Node.js 安装、NVM 管理、NPM 包管理常用命令

🔍
Node.js 安装与版本查看
node -v
查看 Node.js 版本
npm -v
查看 NPM 版本
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
Linux 安装 Node.js 20.x
brew install node
macOS 通过 Homebrew 安装
NVM 版本管理
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
安装 NVM(Node Version Manager)
nvm install 20
安装指定版本 Node.js
nvm use 20
切换到指定版本
nvm ls
列出已安装的版本
nvm alias default 20
设置默认版本
nvm uninstall 18
卸载指定版本
NPM 包管理
npm init
初始化项目(生成 package.json)
npm install <package>
安装依赖包
npm install -g <package>
全局安装包
npm uninstall <package>
卸载依赖包
npm update
更新所有依赖
npm list
列出已安装的包
npm outdated
检查过期的包