本来の目的:ローカル環境でES6を使用
node.jsのバージョン管理ツールnodebrewをインストール
※メリット:複数のnode.jsのバージョンを簡単に切り替えられる。
brewがインストールされているか確認
$ brew -v
【実行結果】インストールされている
Homebrew 2.2.6
Homebrew/homebrew-core (git revision ba38; last commit 2020-02-28)
nodebrewのインストール
$ brew install nodebrew
【実行結果】
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
abseil hdf5@1.10 publish
archiver hdt qp
azcopy hsd seal
bnfc killswitch swift-format
ccheck mockolo swift-sh
cdk8s mtoc tlx
container-structure-test nef vpn-slice
dhall-yaml newrelic-cli xclogparser
forcecli oil zim
git-trim openlibm
==> Updated Formulae
node ✔ less
*
*
(省略)
*
*
Removing: /Users/lancai/Library/Logs/Homebrew/yarn... (100B)
Removing: /Users/lancai/Library/Logs/Homebrew/autoconf... (64B)
Removing: /Users/lancai/Library/Logs/Homebrew/node... (64B)
Removing: /Users/lancai/Library/Logs/Homebrew/rbenv... (64B)
Pruned 1 symbolic links and 2 directories from /usr/local
lancai@oja Desktop %
2分ほどでインストールが完了。
※10分以上かかる場合もあるとのこと
nodebrewのバージョン確認
$ nodebrew
【実行結果】
nodebrew 1.0.1
Usage:
nodebrew help Show this message
nodebrew install <version> Download and install <version> (from binary)
nodebrew compile <version> Download and install <version> (from source)
nodebrew install-binary <version> Alias of `install` (For backword compatibility)
nodebrew uninstall <version> Uninstall <version>
nodebrew use <version> Use <version>
nodebrew list List installed versions
nodebrew ls Alias for `list`
nodebrew ls-remote List remote versions
nodebrew ls-all List remote and installed versions
nodebrew alias <key> <value> Set alias
nodebrew unalias <key> Remove alias
nodebrew clean <version> | all Remove source file
nodebrew selfupdate Update nodebrew
nodebrew migrate-package <version> Install global NPM packages contained in <version> to current version
nodebrew exec <version> -- <command> Execute <command> using specified <version>
Example:
# install
nodebrew install v8.9.4
# use a specific version number
nodebrew use v8.9.4
私のバージョンは8.9.4
みたいです
Node.jsのインストール
実行環境の確認
$ echo $SHELL
【実行結果】
/bin/zsh
/bin/zsh
の場合は以下を入力
$ echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.zshrc
〜ここまでインストール準備完了〜
以下を一つずつ実行
$ source ~/.zshrc
$ nodebrew setup
実行結果
Fetching nodebrew...
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew
========================================
Export a path to nodebrew:
export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================
引き続き以下を実行
$ nodebrew use stable
実行結果
use v12.16.1
$ node -v
実行結果
v12.16.0
Node.jsのバージョンが表示されたので無事にインストール出来たようです。