350

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.

3
  • Which version of node.js are you looking to get installed?
    – bmike
    Feb 11, 2015 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, 2015 at 17:19
  • At this date the reader should go to this answer : stackoverflow.com/a/4158763/48136
    – bric3
    Oct 10, 2018 at 13:21

13 Answers 13

586

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 ✔
node ✔
node@10
node_exporter
nodenv
libbitcoin-node
node-build
node@12 ✔
node@14 ✔
...

And then install the desired version:

brew install node@14

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@14

Sometimes it might be required to link them with the --force and --overwrite options:

brew link --force --overwrite node@14

However, when new node version comes out and you’ll update to it by running brew upgrade, the link will be removed and the most recent node version will be linked instead. To remedy that you might consider adding your desired node version to PATH instead (and restart the shell):

echo 'export PATH="/usr/local/opt/node@14/bin:$PATH"' >> ~/.zshrc

(replace .zshrc with .bashrc or similar, depending on which $SHELL you use)

0
70

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
4
  • Just what I needed Mar 27, 2017 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, 2018 at 10:23
  • didn't work on Mac OS 10.13.5, getting error stackoverflow.com/questions/53043476/…
    – vikramvi
    Oct 29, 2018 at 10:33
  • 1
    how can I install specific version of node, I have install node version "10.17.0" with command brew install node@10, but I need to install "10.15.3".
    – codemilan
    Nov 5, 2019 at 6:03
18

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.

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

3
  • 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. Mar 2, 2015 at 11:04
  • 12
    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. Mar 2, 2015 at 11:12
  • 3
    You might also need to brew unlink node before you brew install node010
    – chananelb
    May 19, 2015 at 9:31
10

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

1
  • Works as of 2017/12! Homebrew 1.4.0-17-gc912d26 Dec 14, 2017 at 18:49
9

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.

1
  • 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, 2018 at 20:23
6

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

1
  • 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, 2017 at 10:03
4

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.

3

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

2
  • +1 this answer. FWIW, I was just able to copy the untarred bin/ folder to my PATH to get this working.
    – shicholas
    Jun 16, 2015 at 18:30
  • 1
    Even better, you can download the .pkg file from there and double-click it to install.
    – Henrik N
    Jun 6, 2019 at 10:52
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

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

1

as an example to downgrade from node@14 to node@12 using homebrew is first you need to install node@12

  brew install node@12

Then unlink node@14

  brew unlink node@14

Then link node@12

  brew link node@12

Then replace the path to bin folder

  echo 'export PATH="/usr/local/opt/node@12/bin:$PATH"' >> ~/.zshrc

Uninstall node@14

  brew uninstall node@14

check the node version

  node -v
1
  • Doesn't Homebrew link everything to /opt/homebrew/bin anyway? If not, you may also need to remove /usr/local/opt/node@14/bin from PATH.
    – nohillside
    Dec 21, 2021 at 8:14
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.

6
  • 1
    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, 2017 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. Mar 16, 2017 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, 2017 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. Mar 17, 2017 at 7:47
  • 1
    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, 2017 at 7:55

You must log in to answer this question.

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