うさぎ好きエンジニアの備忘録

うさぎたちに日々癒されているエンジニアが業務で直面したもの & 個人的な学習メモを残していきます。

nodebrew 使って node.js の環境を構築する

個人的な備忘録です。

nodebrew のインストール

以下のコマンドを実行するだけで終わり。

$ curl -L git.io/nodebrew | perl - setup

.zshrc の修正

nodebrew のインストールが完了したら、.zshrc (人によっては .bashrc) に以下の PATH を追記して反映。

$ echo "export PATH=$HOME/.nodebrew/current/bin:$PATH" >> ~/.zshrc
$ source ~/.zshrc

試しに nodebrew コマンドを実行して、以下の出力が得られたらおk。

$ 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

node.js をインストール

今回は stable / latest のバージョンをインストールする。

  • stable
$ nodebrew install-binary stable
  • latest
$ nodebrew install-binary latest

インストールが完了したら確認。

$ nodebrew ls
v10.15.0
v11.6.0

current: none

インストールはできているので使用するバージョンを設定する (今回は v10.15.0)。

# stable を使用するバージョンに設定
$ nodebrew use v10.15.0
use v10.15.0

# 再確認
$ nodebrew ls
v10.15.0
v11.6.0

current: v10.15.0

最後に node のバージョンをチェック。

$ node -v
v10.15.0