Updating npm to version 6 while using node@8 on macOS with Homebrew

Hey everyone, I’m stuck with an npm update issue. Help!

I’ve got node@8 (LTS) installed via Homebrew on my Mac. It came with npm v5.6.0. I want to upgrade npm to version 6 without messing with node.

I tried npm install -g npm and it seemed to work:

/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
+ [email protected]
added 1 package and updated 3 packages in 9.884s

But when I check npm --version, it still shows 5.6.0. What gives?

which node points to /usr/local/opt/node@8/bin/node, so I guess that’s where the old npm is.

Any ideas how to get npm 6 working with my current node setup? Is there a Homebrew trick I’m missing? Thanks in advance!

hey mate, ran into this before. try this:

  1. remove npm globally: npm uninstall -g npm
  2. install latest npm: brew install npm

this should sort it. if not, check ur PATH. might need to add /usr/local/bin at the start.

good luck!

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:

  1. First, I uninstalled the globally installed npm:
    npm uninstall -g npm

  2. Then, I cleared the npm cache:
    npm cache clean --force

  3. 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.