Managing Node.js Versions With Homebrew
TL;DR Manage Node.js versions with Homebrew by using brew link
and brew unlink
:
$> node -v
v9.5.0
$> brew unlink node
$> brew link --force node@8
$> node -v
v8.9.4
Although you can use dedicated tools to manage your Node.js versions, I’ve got
by just fine using Homebrew’s link
and unlink
commands:
-
Homebrew’s
node
package points at the latest version of Node.js. You can find out exactly which version by runningbrew info node
:$> brew info node node: stable 9.5.0 (bottled), HEAD ...
- Install
node
usingbrew install node
-
Homebrew formulae are available for prior versions of Node.js and follow the
node@<version>
naming convention. You can see exactly which version of Node.js a formula points to by using theinfo
command:$> brew info node@8 node@8: stable 8.9.4 (bottled), HEAD [keg-only] ...
- Install
node@8
usingbrew install node@8
-
With
node
andnode@8
installed we can switch between them like so:$> node -v v9.5.0 # <- node is pointing at the node formula $> brew unlink node $> brew link --force node@8 # --force required as node@8 is a keg-only formula $> node -v v8.9.4 # <- node now points at the node@8 formula
-
To change back to the latest Node.js, just do the opposite to what we’ve just done:
$> brew unlink node@8 $> brew link node $> node -v v9.5.0