I’ve encountered this issue before. The problem is likely due to conflicting npm installations. Here’s a solution that worked for me:
Check your PATH by running echo $PATH. Make sure /usr/local/bin comes before /usr/local/opt/node@8/bin.
If not, modify your PATH in your shell configuration file (.bashrc, .zshrc, etc.):
export PATH=/usr/local/bin:$PATH
Then, run source ~/.bashrc (or your equivalent shell config file).
Now try updating npm again:
npm install -g npm@latest
This should ensure you’re using the correct npm version. If issues persist, consider using a Node version manager like ‘nvm’ for easier version control in the future.
I ran into a similar issue when updating npm on my Mac. The problem is likely that your system is still referencing the old npm version that came bundled with Node.
Here’s what worked for me:
First, I uninstalled the globally installed npm: npm uninstall -g npm
Then, I cleared the npm cache: npm cache clean --force
Finally, I reinstalled npm globally: npm install -g npm@latest
After these steps, npm --version showed the updated version. If you’re still having trouble, you might need to update your PATH to ensure it’s pointing to the correct npm installation.
Also, consider using a version manager like ‘n’ or ‘nvm’ for easier Node.js and npm version management in the future. It’s been a game-changer for me when juggling different project requirements.