LoginSignup
6
3

More than 3 years have passed since last update.

homebrewでnodeモジュールのダウングレード

Last updated at Posted at 2020-03-24

homebrewでダウングレードしたnodeを使用する際に、詰まった部分を残します。

環境

インストール済みのnodeバージョン:13.11.0
インストールしたいnodeバージョン:12.16.1

macOS:10.14.3

nodeバージョン12系をインストール

バージョン指定の方法が12系の場合@12で最新の12系のバージョンがインストールできます。

$ brew install node@12
==> Downloading https://homebrew.bintray.com/bottles/node@12-12.16.1.mojave.bott
==> Downloading from https://akamai.bintray.com/3d/3dee3426e2ea8928d0724a801591a
######################################################################## 100.0%
==> Pouring node@12-12.16.1.mojave.bottle.tar.gz
==> Caveats
node@12 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have node@12 first in your PATH run:
  echo 'export PATH="/usr/local/opt/node@12/bin:$PATH"' >> ~/.bash_profile

For compilers to find node@12 you may need to set:
  export LDFLAGS="-L/usr/local/opt/node@12/lib"
  export CPPFLAGS="-I/usr/local/opt/node@12/include"

==> Summary
🍺  /usr/local/Cellar/node@12/12.16.1: 4,293 files, 57.8MB

12系のバージョンはインストールが完了しました。

しかし、13系のバージョンを残したままインストールすると複数のノードパッケージをインストールできますが、同時に使用できるようにすることはできません。
したがって、既存のパッケージ(ここでは13系)が入っている場合は最初にその紐付きを解除する必要があります。

インストール済みのバージョンの紐付きを解除

以下のコマンドで現在紐付いているバージョンを解除できます。

$ brew unlink node
Unlinking /usr/local/Cellar/node/13.11.0... 0 symlinks removed

使用したいバージョンを紐付ける

今回は12系のnodeバージョンを紐付けたいので以下のように設定します。

$ brew link node@12
Warning: node@12 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@12/bin:$PATH"' >> ~/.bash_profile

紐付けを行なった際に.bash_profileのnodeのパスを設定してくださいと警告が出ているので、設定します。

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

.bash_profileを念のため更新

$ source ~/.bash_profile

最後にnodeのバージョンを確認

$ node -v
v12.16.1

成功です。


余談ですが、今回バージョンを落とした理由は
gatsby-cli v2.11.1をインストールする際に、nodeモジュールが13.11.0の場合インストールに失敗してしまう事がきっかけでした。

ダウングレードにより、無事gatsby-cliの導入もできました。

$ gatsby --version
Gatsby CLI version: 2.11.1
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3