仕事でnode.jsにどっぷり浸かったのもあり、検証したいこともあり、使って見たいタスクランナーもあり、Macにnode.jsを入れることにした。
webで調べると、nodebrewを使うとバージョン管理できて便利そう。幸いhomebrewはもう入れてあった。
インストール
brew install nodebrew
xcrun: error: active developer path ("/Library/Developer/CommandLineTools") does not exist Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools. See `man xcode-select` for more details.
エラー。webで調べてみるとXcodeがインストールされているはずのパスが実態とずれてしまうことがあるらしい。
正しいパスに変更したいのは山々なんだけど、正しいパスが何なのかわからない……。
StackOverflowによれば、sudo xcode-select --reset
が効いたとのこと。これなら正しいパス知らなくても使えるネ!
念のため、xcode-select -print-path
してみると、ちゃんと変更されたみたい。
brew install nodebrew
Error: You have not agreed to the Xcode license. Please resolve this by running: sudo xcodebuild -license accept
今度はライセンスに同意してないとのこと。これはコマンドラインが丁寧に書いてある。sudo xcodebuild -license accept
を実行した後改めてbrew install nodebrew
無事インストールされた。
パスを通す
$ echo 'export PATH=$PATH:$HOME/.nodebrew/current/bin' >> ~/.bash_profile
ユーザーフォルダ直下の不可視ファイル.bashprofileに書き込みするらしい。テキストエディタで開いたらちゃんと書かれてた。
ここでセッションリスタートする。
インストールされたか確認。
nodebrew -v
node本体のダウンロード
利用可能バージョンの確認。
nodebrew ls-remote
仕事で使っている8.9.4をインストール……しようとしたらエラー。
nodebrew install-binary v8.9.4 Fetching: https://nodejs.org/dist/v8.9.4/node-v8.9.4-darwin-x64.tar.gz Warning: Failed to create the file Warning: /Users/user_name/.nodebrew/src/v8.9.4/node-v8.9.4-darwin-x64.tar.gz: Warning: No such file or directory
mkdirしないといけない、と書いてあるサイトが最初に出てくるんだけど、そんなインストールツールあるのかよ……と絶望してインストール直後のログを眺めてたら、英語でちゃんと書いてあった。
==> Caveats You need to manually run setup_dirs to create directories required by nodebrew: /usr/local/opt/nodebrew/bin/nodebrew setup_dirs Add path: export PATH=$HOME/.nodebrew/current/bin:$PATH
改めてnodebrew install-binary v8.9.4
してインストール。今度は成功。利用開始。
mogami74Mac:~ mogami74$ nodebrew use v8.9.4 use v8.9.4 mogami74Mac:~ mogami74$ node -v v8.9.4
参考サイト
active developer path...does not existを解決 - Qiita
Homebrew で nodebrew をインストールしたら少々はまった - ngzmのブログ
こちらのサイトにはちゃんと、手動で /usr/local/opt/nodebrew/bin/nodebrew setup_dirs
叩くように紹介されている。