You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js 4.2.6无法更新至最新版本,npm运行报错求助

Fixing npm Error with Node.js v4.2.6 When Installing Angular CLI

Hey there, let's work through this issue together. That error message spells out the core problem: Node.js v4.2.6 has a known bug that breaks npm, and half-hearted updates or reinstalls aren't cutting it. Let's do a proper cleanup and get a working setup going.

Step 1: Fully Uninstall Node.js and npm (No Residues Left!)

Partial uninstalls often leave behind files that cause lingering issues. Let's wipe everything clean based on your system:

Windows

  • Head to Control Panel > Programs > Uninstall a program, find Node.js, and uninstall it.
  • Delete these folders if they exist:
    • C:\Program Files\nodejs
    • C:\Program Files (x86)\nodejs
    • Your user folder (e.g., C:\Users\YourName)里的 .npmrc, node_modules, 和 .npm 文件夹
  • Open System Properties > Advanced > Environment Variables, find the PATH variable, and remove any entries pointing to Node.js.

macOS

  • If you installed Node via Homebrew: run brew uninstall node in terminal.
  • For a full cleanup, run these commands (use sudo if prompted):
    sudo rm -rf /usr/local/{bin/{node,npm},lib/node_modules/npm,lib/node,share/man/*/node.*}
    

Linux (Debian/Ubuntu)

  • Run these commands to purge existing installations:
    sudo apt-get purge nodejs npm
    sudo apt-get autoremove
    
  • Delete leftover folders:
    sudo rm -rf /usr/local/lib/node_modules
    

Step 2: Install a Working Node.js Version (At Least v4.7.0)

I highly recommend using Node Version Manager (nvm) for this—it lets you switch between Node versions easily and avoids messy system-wide conflicts.

Using nvm (All Systems)

  1. Install nvm using its official setup script (you can grab the latest command from the nvm project repository).
  2. Restart your terminal to load nvm properly.
  3. Install the minimum required version:
    nvm install 4.7.0
    
  4. Set it as your default version so it loads every time you open terminal:
    nvm alias default 4.7.0
    

Without nvm

If you prefer a direct install, download the Node.js v4.7.0 installer for your system from the official Node.js release archives, run it, and make sure the installation adds Node to your system PATH.

Step 3: Verify Your Installation

Open a fresh terminal window and run these commands to confirm everything works:

node -v
# Should output v4.7.0 or higher
npm -v
# Should show a valid npm version without errors

Step 4: Install Angular CLI

Now that your Node/npm setup is fixed, install Angular CLI globally:

npm install -g @angular/cli

Verify the install with:

ng version

Quick Note for Future Reference

If you plan to use newer versions of Angular later, you'll need to upgrade Node.js to a more recent LTS version (like 16.x or 18.x)—Angular's newer releases have higher minimum Node version requirements. But for now, v4.7.0 will get you past this npm error.

内容的提问来源于stack exchange,提问作者Bhawna Saroha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:27:57