189

The latest version of NodeJs right now is 0.4.1

The command brew install node right now, installs 0.2.6 - which is not ideal. I would like 0.4.1

I've looked at this list of commands for brew and tried brew install --HEAD node

But that installs node 0.5-pre.

Why isn't brew installing the right version and how can I force it to get the right one?

At this stage, it looks like it would actually be easier just to download the src and install it manually. But I would like to know what's going on with Brew.

myhd
  • 324
  • 3
  • 22
PandaWood
  • 7,758
  • 8
  • 46
  • 52
  • I am curious. What is the difference between installing via Homebrew and installing from the package downloaded from [nodejs.org](http://nodejs.org)? – yihangho Jun 28 '13 at 15:48

16 Answers16

347

Run commands below, in this order:

brew update
brew doctor
brew upgrade node

Now you have installed updated version of node, and it's probably not linked. If it's not, then just type: brew link node or brew link --overwrite node

Bryan Downing
  • 14,646
  • 3
  • 40
  • 59
Andrey Bodoev
  • 4,061
  • 2
  • 25
  • 19
154

After installation/upgrading node via brew I ran into this issue exactly: the node command worked but not the npm command.

I used these commands to fix it.

brew uninstall node
brew update
brew upgrade
brew cleanup
brew install node
sudo chown -R $(whoami) /usr/local
brew link --overwrite node
brew postinstall node

I pieced together this solution after trial and error using...

stevek-pro
  • 13,672
  • 14
  • 81
  • 134
Eric Walsh
  • 2,885
  • 1
  • 14
  • 21
  • 1
    Thank you! Had the exact same issue, and this solved it. – elsurudo Mar 02 '15 at 12:46
  • Much appreciated, saved me hours of debugging – Abe Petrillo Aug 29 '15 at 22:14
  • 7
    `sudo brew postinstall node` will throw an error unless brew is owned by root (not recommended). I don't think it should be needed if you already did `sudo chown -R $(whoami) /usr/local`. You should be able to just run `brew postinstall node`. – Sam Fen Dec 14 '15 at 19:47
  • Thank you very much! Saved hours of checking on this. – Randula May 08 '16 at 17:23
  • 2
    @SamFen 's right. `sudo` not needed. I first ran the accepted answer before I gave this listing of commands a go. Afterwards I ran `node -v` and everything seems fine now. – 6754534367 May 19 '16 at 18:15
  • 1
    Use sudo chown -R $(whoami) $(brew --prefix)/* instead of sudo chown -R $(whoami) /usr/local – Troy Jun 23 '18 at 19:42
  • 1
    This worked for me. I did what @TroyDCThompson recommended `sudo chown -R $(whoami) $(brew --prefix)/*` as I was getting `Operation not permitted`. – thurzo101 Jul 31 '18 at 19:30
136

Have you run brew update first? If you don't do that, Homebrew can't update its formulas, and if it doesn't update its formulas it doesn't know how to install the latest versions of software.

Lily Ballard
  • 176,187
  • 29
  • 372
  • 338
  • 2
    Right, I'd tried 'brew update node' but I see now you are right. It didn't occur to me because the doco says that 'brew update' would update the brew software - which would seem to make no difference. But it mentions 'formulea' - which is just a (frankly) stupid word for what is basically it's 'library of software versions'. I can do 'brew info node' to find out what version it's going to install. It's set to 0.4.0 so I ended up installing from src anyway, but this is right. Thank you. – PandaWood Feb 20 '11 at 12:12
  • When it says "update the brew software" it doesn't mean update software that brew has installed - it means update brew itself, as well as its library of Formulae. – Lily Ballard Feb 20 '11 at 22:58
24

Sometimes brew update fails on me because one package doesn't download properly. So you can just upgrade a specific library like this:

brew upgrade node

https://gist.github.com/3005832

Lance
  • 69,908
  • 82
  • 257
  • 454
24

Also, try to deactivate the current node version after installing a new node version. It helps me.

nvm deactivate

This is removed /Users/user_name/.nvm/*/bin from $PATH

And after that node was updated

node --version
v10.9.0
AlexSh
  • 1,219
  • 12
  • 12
11

I had to do brew link --overwrite node after brew install node to update from 0.4 to 0.8.18

ojreadmore
  • 1,445
  • 2
  • 17
  • 33
10

If you have installed current node via Homebrew, just use these commands.

brew update
brew upgrade node

Check node version by

node -v

Harikrishnan
  • 9,108
  • 9
  • 83
  • 125
10
  1. node -v will show you the current version.
  2. npm -v will show you the current version.
  3. brew link --overwrite --dry-run node will force the link and overwrite all conflicting files.
  4. brew install node do a fresh installation.
  5. brew update
  6. brew upgrade node
  7. brew link --overwrite node

    or

    brew link node

Node Upgrade Procedure are below

the Tin Man
  • 155,156
  • 41
  • 207
  • 295
Mahendra Rao
  • 111
  • 1
  • 3
  • This might be helpful to some -/usr/local/include/node is not writable https://www.codegrepper.com/code-examples/javascript/Error%3A+Could+not+symlink+include%2Fnode%2Fcommon.gypi+%2Fusr%2Flocal%2Finclude%2Fnode+is+not+writable. – Shubh Sep 01 '21 at 07:29
9

Try to use "n" the Node extremely simple package manager.

> npm install -g n

Once you have "n" installed. You can pull the latest node by doing the following:

> n latest

I've used it successfully on Ubuntu 16.0x and MacOS 10.12 (Sierra)

Reference: https://github.com/tj/n

Reuben
  • 125
  • 1
  • 3
5

Just used this solution with Homebrew 0.9.5 and it seemed like a quick solution to upgrade to the latest stable version of node.

brew update

This will install the latest version

brew install node

Unlink your current version of node use, node -v, to find this

brew unlink node012

This will change to the most up to date version of node.

brew link node

Note: This solution worked as a result of me getting this error:

Error: No such keg: /usr/local/Cellar/node

user2096561
  • 126
  • 2
  • 4
4

I did this on Mac OSX Sierra. I had Node 6.1 installed but Puppetter required Node 6.4. This is what I did:

brew upgrade node
brew unlink node
brew link --overwrite node@8
echo 'export PATH="/usr/local/opt/node@8/bin:$PATH"' >> ~/.bash_profile

And then open a new terminal window and run:

node -v
v8.11.2

The --overwrite is necessary to override conflicting files between node6 and node8

Daniel Viglione
  • 6,804
  • 7
  • 56
  • 89
2

You can use nodebrew. It can switch node versions too.

c-project
  • 51
  • 3
2

if the node is not installed then

brew install node

If you have an older version of the node installed then remove it and re-install freshly that's the only suitable way.

Make sure to add the path in the environment file.

Hims1911
  • 21
  • 3
1

If you're willing to remove the brew dependency, I would recommend nvm - I can't really recommend it over any other versioning solution because I haven't needed to try anything else. Having the ability to switch instantly between versions depending on which project you're working on is pretty valuable.

Jon z
  • 3,744
  • 1
  • 27
  • 20
1

Just go old skool - https://nodejs.org/en/download/current/ From there you can get the current or LTS versions

danharsanyi
  • 406
  • 5
  • 5
0

sudo n latest

OR

brew update

brew upgrade node

Reference: https://bytearcher.com/articles/ways-to-get-the-latest-node.js-version-on-a-mac/