Skip to content

Instantly share code, notes, and snippets.

@hansanghoon
Created February 20, 2018 02:19
Show Gist options
  • Save hansanghoon/8b609e9a2f67693c4a7b273b0571c04d to your computer and use it in GitHub Desktop.
Save hansanghoon/8b609e9a2f67693c4a7b273b0571c04d to your computer and use it in GitHub Desktop.
Change nodejs link to a specific version using Homebrew on macOS

Note

You can downgrade nodejs to a specific version installed on your mac using brew before.

Downgrade

For example, I want to downgrade node from 9(current/head version) to 6. Simplest way is just unlink and link. Since node@6 is keg-only, we use brew link --force command.

$ node --version
v9.5.0
$ brew unlink node
Unlinking /usr/local/Cellar/node/9.5.0... 7 symlinks removed
$ brew link node@6
Warning: node@6 is keg-only and must be linked with --force
Note that doing so can interfere with building software.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/node@6/bin:$PATH"' >> ~/.zshrc
$ brew link node@6 --force
Linking /usr/local/Cellar/node@6/6.12.3... 7 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/node@6/bin:$PATH"' >> ~/.zshrc

Set specific version

check for previously installed version

$ brew info node@6
node@6: stable 6.12.3 (bottled), HEAD [keg-only]
Platform built on V8 to build network applications
https://nodejs.org/
/usr/local/Cellar/node@6/6.9.1 (3,860 files, 41.2MB)
  Poured from bottle on 2016-11-28 at 10:58:17
/usr/local/Cellar/node@6/6.9.2 (3,860 files, 41.2MB)
  Poured from bottle on 2016-12-26 at 11:03:56
/usr/local/Cellar/node@6/6.9.4 (3,891 files, 41.3MB)
  Poured from bottle on 2017-01-16 at 13:22:49
/usr/local/Cellar/node@6/6.10.0_1 (3,145 files, 41.6MB)
  Poured from bottle on 2017-03-09 at 16:05:41
/usr/local/Cellar/node@6/6.10.1 (3,145 files, 41.7MB)
  Poured from bottle on 2017-03-27 at 15:13:59
/usr/local/Cellar/node@6/6.10.2 (3,073 files, 41.3MB)
  Poured from bottle on 2017-04-10 at 11:43:43
/usr/local/Cellar/node@6/6.10.3 (3,075 files, 41.3MB)
  Poured from bottle on 2017-05-08 at 09:55:59
/usr/local/Cellar/node@6/6.10.3_1 (3,786 files, 45.9MB)
  Poured from bottle on 2017-06-05 at 13:30:51
/usr/local/Cellar/node@6/6.10.3_2 (3,780 files, 45.9MB)
  Poured from bottle on 2017-06-09 at 10:45:08
/usr/local/Cellar/node@6/6.11.0 (3,780 files, 45.9MB)
  Poured from bottle on 2017-06-27 at 10:08:28
/usr/local/Cellar/node@6/6.11.1 (3,780 files, 45.3MB)
  Poured from bottle on 2017-07-14 at 17:31:02
/usr/local/Cellar/node@6/6.11.1_1 (4,149 files, 46.6MB)
  Poured from bottle on 2017-07-27 at 10:50:32
/usr/local/Cellar/node@6/6.11.3 (4,149 files, 47.3MB)
  Poured from bottle on 2017-09-08 at 17:54:50
/usr/local/Cellar/node@6/6.11.4 (4,149 files, 47.2MB)
  Poured from bottle on 2017-10-10 at 13:09:11
/usr/local/Cellar/node@6/6.11.4_1 (3,827 files, 46.4MB)
  Poured from bottle on 2017-10-18 at 10:06:44
/usr/local/Cellar/node@6/6.12.0 (5,010 files, 50.3MB)
  Poured from bottle on 2017-11-10 at 14:19:49
/usr/local/Cellar/node@6/6.12.2 (5,123 files, 50.6MB)
  Poured from bottle on 2017-12-26 at 13:38:27
/usr/local/Cellar/node@6/6.12.3 (5,123 files, 50.6MB) *
  Poured from bottle on 2018-01-15 at 16:54:33
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/node@6.rb

use brew switch command and brew link again.

$ brew switch node@6 6.11.1_1
Cleaning /usr/local/Cellar/node@6/6.10.3_2
Cleaning /usr/local/Cellar/node@6/6.11.1_1
Cleaning /usr/local/Cellar/node@6/6.9.1
Cleaning /usr/local/Cellar/node@6/6.10.2
Cleaning /usr/local/Cellar/node@6/6.10.3
Cleaning /usr/local/Cellar/node@6/6.12.0
Cleaning /usr/local/Cellar/node@6/6.11.1
Cleaning /usr/local/Cellar/node@6/6.11.0
Cleaning /usr/local/Cellar/node@6/6.10.3_1
Cleaning /usr/local/Cellar/node@6/6.9.4
Cleaning /usr/local/Cellar/node@6/6.9.2
Cleaning /usr/local/Cellar/node@6/6.12.2
Cleaning /usr/local/Cellar/node@6/6.10.1
Cleaning /usr/local/Cellar/node@6/6.12.3
Cleaning /usr/local/Cellar/node@6/6.10.0_1
Cleaning /usr/local/Cellar/node@6/6.11.4_1
Cleaning /usr/local/Cellar/node@6/6.11.4
Cleaning /usr/local/Cellar/node@6/6.11.3
Opt link created for /usr/local/Cellar/node@6/6.11.1_1
$ node --version
zsh: command not found: node
$ brew link node@6 --force
Linking /usr/local/Cellar/node@6/6.11.1_1... 7 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/node@6/bin:$PATH"' >> ~/.zshrc
$ node --version
v6.11.1

To current version

just brew unlink and brew link

$ brew unlink node@6
Unlinking /usr/local/Cellar/node@6/6.11.1_1... 7 symlinks removed
$ brew link node
Linking /usr/local/Cellar/node/9.5.0... 7 symlinks created
$ node --version
v9.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment