Guilherme Salome
Guilherme Salome

Reputation: 2039

Node using wrong version after Brew Install

I'm using a Macbook with the latest macOS (10.12.3), and I installed Homebrew by running:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After that I installed node:

brew install node

And tried to upgrade it:

> brew upgrade node
> Error: node 7.8.0 already installed

I got an error saying the version 7.8.0 is already installed, that was expected since I had just installed the most recent version.

Problem: on the terminal I ran:

> node --version
> v4.4.5

and got back an old version that apparently was already installed. Also, when I install some new package through npm I get a warning saying the package requires an newer version of node.

Question: I seem to have both versions of node installed on my mac, how can I use the most current one? And how can I uninstall all other older node versions?

Thank you very much for your help!

Upvotes: 23

Views: 25496

Answers (4)

kai_onthereal
kai_onthereal

Reputation: 488

  1. Uninstall Node:

brew uninstall node

  1. Install LTS version

where: https://nodejs.org/en/download/package-manager

why: https://nodejs.org/en/about/previous-releases

LTS release status is "long-term support", which typically guarantees that critical bugs will be fixed for a total of 30 months. Production applications should only use Active LTS or Maintenance LTS releases.

brew install node@20 (LTS at the time)

  1. Since Homebrew installs Node.js 20 in a separate location, you need to link it to make it the default Node version

brew link --overwrite node@20

  1. Check Node version

node -v or node --version

-> v20.xx.x

Upvotes: 0

Anish Mandal
Anish Mandal

Reputation: 47

  1. brew install node
  2. brew upgrade node
  3. node -v
  4. sudo n latest
  5. node -v

1st step will install node using homebrew then you need to upgrade node using homebrew as in step 2 mentioned above , after then when you check node version you'll see latest node already installed but still works on older version, then finally when you run step 4 cmd it will install the latest node and if you check now this will show you the latest node version and ya you are ready to go now . This worked for me

Upvotes: 4

Obromios
Obromios

Reputation: 16383

I had a similar problem, and the Salome answer fixed it, but, when I opened a new shell, it reverted to an older version of node. If I typed node list I found I still had a number of versions, despite following Salome's instructions to remove all the old versions.

I could fix it by typing nvm use v7.8.0 , but that does not work for a new shell. I was able to fix it permanently following this SO answer

nvm alias default 7.8.0

Upvotes: 1

Guilherme Salome
Guilherme Salome

Reputation: 2039

My problem was solved following @theWanderer4865 suggestions in the comments.

First, I uninstalled the node version I had installed through brew: in the terminal I executed:

> brew cleanup
> brew uninstall node

Second, I removed all other node versions I had installed by running:

> rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,n‌​ode*,man1/node*}

Third, install node again using nvm:

> nvm install node

Upvotes: 28

Related Questions