183

I'm using brew. I have node installed, using brew. I want to use an earlier version of node.

Online, I find instructions such as, for example:

cd /usr/local/Library/Formula
brew remove node --force
brew versions node
git checkout 83988e4 /usr/local/Library/Formula/node.rb
brew install node

The problem I have with this is that brew doesn't seem to have a versions subcommand:

$ brew versions node
Error: Unknown command: versions
$ brew --version
0.9.5

I'm new to brew. Do I need to enable the versions subcommand somehow? Should I use a different subcommand instead? Is there a completely different method I should try?

I'm running OS X Yosemite (10.10.1); brew 0.9.5.

  • Which version of node.js are you looking to get installed? – bmike Feb 11 '15 at 17:12
  • My boss tells me 10.32. I guess he means 0.10.32. I have 0.12.0 installed right now. – dave4420 Feb 11 '15 at 17:19
  • At this date the reader should go to this answer : stackoverflow.com/a/4158763/48136 – Brice Oct 10 '18 at 13:21

12 Answers 12

294

These days if you want to install a different version of node you do it this way:

First search for your desired package:

brew search node

This might give you the follow results:

heroku/brew/heroku-node ✔
llnode
node@6 ✔
nodebrew
leafnode
node ✔
node@8 
....

And then install the desired version:

brew install node@6

Also remember that you can install more than 1 node package at the same time, but you cannot have them available at the same time. So if you have the latest/generic node package already installed you need to unlink it first:

brew unlink node

And then you can link a different version:

brew link node@6

For some older node versions (which are keg-only), it might be required to link them with the --force and --overwrite options:

brew link --force --overwrite node@6
  • 7
    best answer on here. – chovy Nov 7 '15 at 19:05
  • 2
    Note that you may be prompted to "unlink" an existing version of node before you can successfully install one of the other versions that was listed (per instructions above). By "unlinking" you are leaving the other version physically installed on your system but the one you install (after the unlink) will become the "default" version on your system. For example, you might have to type brew unlink node if you had installed brew install node. Then you could do brew install homebrew/versions/node4-lts (which you should see as a version listed per the instructions in this answer). – xmnboy Jul 10 '16 at 23:24
  • 1
    Instead of homebrew/versions/node06 it's now homebrew/versions/node6-lts. Also do brew link node6-lts. – akauppi Nov 9 '16 at 8:08
  • 1
    I've updated my answer to reflect latest brew changes. Thanks! – Paweł Gościcki Dec 5 '16 at 22:50
  • 2
    but how can we install a specific version like node 8.2.1 using brew? – Nadav B Jan 12 '18 at 13:04
29

Here's step by step.

To see your current node version

$ node --version

To see available node versions

$ brew search node

To unlink from current version

$ brew unlink node

Install any version e.g. 8

$ brew install node@8

To link installed version

$ brew link node@8

To see your current node version (again)

$ node --version
  • Just what I needed – Brian Colavito Mar 27 '17 at 14:47
  • How to solve this issue ? brew link node@10 Warning: node@10 is keg-only and must be linked with --force If you need to have this software first in your PATH instead consider running: echo 'export PATH="/usr/local/opt/node@10/bin:$PATH"' >> ~/.bash_profile – vikramvi Oct 29 '18 at 10:23
  • didn't work on Mac OS 10.13.5, getting error stackoverflow.com/questions/53043476/… – vikramvi Oct 29 '18 at 10:33
13

As of this PR to homebrew/versions and this PR to homebrew, the answers involving brew tap homebrew/versions or *-lts packages no longer work.

The correct answer is now:

brew install node@<version>

Where <version> is 0.10, 0.12, 4, etc. For example, to install Node.js v6 (as of this writing, the most recent LTS version):

brew install node@6

You may need to run brew update prior to these commands to ensure that these new versioned formulae are available. If you have another version of the node formula installed, you'll also need to run brew unlink node first.

11

brew versions has to be installed at some point after you install brew.

$ brew tap homebrew/boneyard

You can then use the brew versions command as the instructions assume.

  • 4
    homebrew/boneyard is outdated and going to be replaced with github.com/Homebrew/homebrew-versions as of March 2015. Install via brew tap homebrew/versions. – Jakub Holý Mar 2 '15 at 11:04
  • 11
    With homebrew/versions you will get versioned name of the package: brew search node => leafnode node node010 node04 node06 node08 nodebrew .... So do brew install node010 followed by brew link --overwrite node010 to install the 0.10 version of Node.JS. – Jakub Holý Mar 2 '15 at 11:12
  • 3
    You might also need to brew unlink node before you brew install node010 – chananelb May 19 '15 at 9:31
9

FYI, if you previously had the old version installed and haven't run brew cleanup (which deletes old versions), you can switch with something like brew switch node 5.7.0

All installed versions of node can be listed by running brew info node or ls -l /usr/local/Cellar/node/

See the brew command cheat sheet: http://ricostacruz.com/cheatsheets/homebrew.html

  • Works as of 2017/12! Homebrew 1.4.0-17-gc912d26 – Jason Harrison Dec 14 '17 at 18:49
5

If you need it just specifically for Node, you can use nvm. It is very convenient if you work with Node a lot.

  • According to nvm docs brew and nvm are not a supported combo. I commented on this here. github.com/angular/angular-cli/issues/… I'd be interested in hearing any war stories on this. Because on the surface I seem to have this working despite the fact it's "not supported" – JGFMK Jun 28 '17 at 10:03
3

If you faced troubles with homebrew to install any version of node, you can just download .pkg file for OSX from https://nodejs.org/dist/[VERSION_YOU_NEED]. This is only helps me to reinstall node

2

You can do it without homebrew.

You can uninstall and then install the node manually.

You have to download your current running version. Here is the list.

Download the node-v{your-current-version-number}.tar.gz, extract it and then go to command line.

cd node-v{your-current-version-number}
./configure
make
sudo make install

To uninstall it sudo make uninstall

Then download the version you want to install and follow same steps above.

From this blog post

  • +1 this answer. FWIW, I was just able to copy the untarred bin/ folder to my PATH to get this working. – shicholas Jun 16 '15 at 18:30
2

There are a lot of answers here and other places that say to use homebrew-versions, but that gives you very limited options for which version of Node you can install.

It's much easier to use NVM and it allows you to switch between versions very easily.

homebrew install nvm

Then follow the instructions in the caveats -- mkdir ~/.nvm and add two lines to your .bash_profile and source .bash_profile

Then simply run nvm install <version> for all the versions you need. Then nvm use <version> to switch.

  • This is not the accepted answer, but it is the only one that worked for me. I wish I had tried this one the first, because I would have saved a lot of time. – Alex Jul 15 '18 at 20:23
1

Let's imaging that you have 0.12.* version. To install (downgrade) 0.10 version of node throw the brew in OSX, you have to:

$ sudo brew tap homebrew-versions
$ brew unlink node
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-versions/master/node010.rb
$ node -v

List of all node versions is here

0

https://nodejs.org/en/blog/release/

You can go here and install the version you need.

Before installing you might want to run brew unlink node to unlink the current version.

  • What would the advantage be of doing it this way, as opposed to using brew (as several other answers describe) or uninstalling node and then manually installing it (as @Terente-Ionut-Alexandru's answer described)? – John N Mar 16 '17 at 10:47
  • @JohnN brew versions is deprecated as of now.Its alternatives are not very easy to understand. Also, it is kinda complex through brew to install the exact version. – Anant Simran Singh Mar 16 '17 at 11:17
  • @Paweł-Gościcki's answer (the highest rated, with 140 votes) seems very easy to understand, and not at all complex - which matches my recent experience with brew and different versions of formulae. My point is that your answer doesn't seem to add to anything that hasn't already been said in other answers - unless there's a reason to unlink+manually install rather than uninstall+manually install, as Terente suggested? – John N Mar 16 '17 at 11:59
  • @JohnN That ofcourse, is easy to understand . But you will be limited by options that brew search gives. For eg. if you want node 4.4.6 exactly but the brew will only provide a node@4 option. Hence. – Anant Simran Singh Mar 17 '17 at 7:47
  • There are, I think, 3 decent answers to the question: (1) use brew, (2) use nvm, and (3) uninstall and manually install. What I'm trying to get you to do is explain why your answer adds to these existing answers. Why do you feel that unlinking+manually installing is preferable to the existing answers? Specifically, why do you feel that *unlinking*+manually installing is better than *uninstalling*+manually installing, as Terente's answer suggests? – John N Mar 17 '17 at 7:55
0

The preferred way in the NodeJS world is using the tool n

  • Installation: npm install -g n
  • Install Node 8.8.4 n 8.8.4
  • List all your locally available node versions and chose one: n

It seems similar to nvm, but I had issues with nvm, and n worked out of the box.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .