主题
Linux 平台安装 Node.js
Claude Code、CodeX 和 Gemini CLI 都需要 Node.js 18+ 运行环境。
提示
如果已安装 Node.js 18 或更高版本,可跳过此章节。验证命令:node -v
Ubuntu / Debian
使用 NodeSource 仓库(推荐):
bash
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs验证:
bash
node --version
npm --versionCentOS / RHEL
bash
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs验证:
bash
node --version
npm --versionFedora
bash
sudo dnf install -y nodejs npm验证:
bash
node --version
npm --versionArch Linux
bash
sudo pacman -S nodejs npm验证:
bash
node --version
npm --version使用 NVM 管理多版本(进阶)
安装 NVM(Node Version Manager):
bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc安装并使用 LTS 版本:
bash
nvm install --lts
nvm use --lts
nvm alias default node常见问题
权限问题
配置 npm 使用用户目录:
bash
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc系统自带版本过旧
如果系统自带的 Node.js 版本过低,使用 NodeSource 仓库或 NVM 安装最新 LTS 版本。
下一步
安装完成后,继续安装 AI 编程工具: