20

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!

Guilherme Salomé
  • 1,899
  • 4
  • 19
  • 39
  • Have you run brew cleanup and restarted the shell? – theWanderer4865 Apr 04 '17 at 22:20
  • After running into these problems I came across `nvm`. I installed it, but when I tried `nvm use node` or `nvm use 7.8.0` it gives me the error that node itself is not installed (in the first case), and that the version is not installed in the second case. – Guilherme Salomé Apr 04 '17 at 22:21
  • @theWanderer4865 hey, thanks for the suggestion, let me try that. I ran `brew cleanup`, it seemed to have executed by didn't give me anything in response. After restarting the shell `node --version` still gives me the old node. – Guilherme Salomé Apr 04 '17 at 22:22
  • You should uninstall the version you installed with homebrew because it can cause issues with how nvm works - there is a section in the docs (if memory serves) about dealing with homebrew related issues. – theWanderer4865 Apr 04 '17 at 22:24
  • @theWanderer4865 thanks again. So far I ran `brew uninstall node`, to remove the brew version of node. And then I followed this [stack](http://stackoverflow.com/questions/11177954/how-do-i-completely-uninstall-node-js-and-reinstall-from-beginning-mac-os-x) by running `rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}`, which seems to have removed the older version of node as well. Now I will try installing with nvm. – Guilherme Salomé Apr 04 '17 at 22:30
  • That should be the ticket, I had to go through this a few months ago when re-installing nvm after a brief period of using just home brew node. – theWanderer4865 Apr 04 '17 at 22:31
  • @theWanderer4865 I ran `nvm install node` but it failed, twice. Not sure how to proceed now. – Guilherme Salomé Apr 04 '17 at 22:41
  • You probably have to specify the version. Something like nvm install 7.8.0 – theWanderer4865 Apr 04 '17 at 22:42
  • @theWanderer4865 the failure seems to be due to downtime on nodejs.org webpage. The downloads are not working. I'll try later, and then post an answer here. Thank you for your help! – Guilherme Salomé Apr 04 '17 at 22:56

3 Answers3

25

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
Guilherme Salomé
  • 1,899
  • 4
  • 19
  • 39
  • 3
    And `nvm` itself can be installed following the [official instructions](https://github.com/creationix/nvm#install-script), which, at the time of writing, was running `curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash` on the terminal. Now, to install `curl` ... haha – Guilherme Salomé Aug 16 '18 at 22:03
  • Thanks so much, I had this same issue but with versions 8 (local) and 12 (brew). Following these steps solved it. – ryanwc Jun 13 '19 at 02:35
  • thanks! this was what did it for me. worth saying the `rm -rf` command didn't match anything when I ran it. But the steps still solved it for me. – Matthew Goodwin Feb 02 '22 at 17:34
4
  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

  • 2
    `sudo n latest` won't update the brew version. You are updating the non-brew (mac) version of node. – Code Lover Feb 06 '21 at 05:19
  • This worked for me. After recently upgrading node using brew to `18.2.0`. I was getting `/var/folders/l_/.../T/yarn--.../node: line 3: /usr/local/Cellar/node/18.0.0/bin/node: No such file or directory /var/folders/l_/.../T/yarn--.../node: line 3: exec: /usr/local/Cellar/node/18.0.0/bin/node: cannot execute: No such file or directory` in Mac OS. – FutureJJ May 31 '22 at 10:42
1

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
Obromios
  • 15,408
  • 15
  • 72
  • 127