How do I downgrade node or install a specific previous version using homebrew?

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.


Solution 1:

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:

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

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

Solution 2:

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