LoginSignup
0
0

More than 3 years have passed since last update.

Macでnodebrewを使用したnodeのインストールと設定

Posted at

(前手順)pkgで入れたnodeの削除 (入れてた場合)

こちらの記事を参考に削除を実施。

$ lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom \
| while read i; do
  sudo rm /usr/local/${i}
done

lsbomコマンドとは

BOMファイルの内容を表示するコマンド。BOMファイルとは、
「Mac OS X Bill of Materials File」のことで、Apple社固有のファイル。
インストーラ(Installer.app)を使用するMacOS X標準のパッケージファイルに含まれている。

(参考:lsbom- BOMファイルの内容を表示する)

$ sudo rm -rf /usr/local/lib/node \
     /usr/local/lib/node_modules \
     /var/db/receipts/org.nodejs.*

1.nodebrewインストールと環境変数の設定

  • ターミナルから、brewでnodebrewをインストール
$ brew install nodebrew
  • 正常にインストールされたか確認
$ nodebrew -vnodebrew -v
  • bash_profileにnode関連のディレクトリパスを追加
    ~./配下を汚さないように、以下のように設定。
NODEBREW_HOME=/usr/local/var/nodebrew/current
export NODEBREW_HOME
export NODEBREW_ROOT=/usr/local/var/nodebrew

/usr/local/var/nodebrewディレクトリがない場合は作成。
/usr/local/var/nodebrew/currentは使用するバージョンのnodeディレクトリのシンボリックリンクとなる。

(/usr/local/var/nodebrew/currentをlsした例)

$ ls -l /usr/local/var/nodebrew/current
lrwxr-xr-x  1 hoge-pc  admin  35  6 12 15:24 /usr/local/var/nodebrew/current -> /usr/local/var/nodebrew/node/v11.9.0
  • bash_profileに追加後反映
$ source ~/.bash_profile

2.nodeのインストール

  • 以下のnodebrewコマンドを実行
# 最新版を入れる場合
$ nodebrew install-binary latest

# バージョン指定で入れる場合
$ nodebrew install-binary <バージョン>
# 例
$ nodebrew install-binary v11.9.0
  • 正常にインストールされたか確認
$ nodebrew ls
  • 現在使用するnodeバージョンを設定する。
nodebrew use <バージョン名>
# 例
$ nodebrew use v11.9.0

複数のバージョンをインストールして、バージョンを切り替える場合も
上記のuseコマンドを使用する。

  • 指定したnodeバージョンが使用可能な状態になっているか確認
$ node -v

(Tips) nodebrewコマンド

  • インストール可能なnodeのバージョンを知りたい場合
$ nodebrew ls-remote
0
0
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
0
0