LoginSignup
54
50

More than 5 years have passed since last update.

Homebrewからnodebrewをインストールして、Node.jsをインストールするまで

Last updated at Posted at 2016-12-15

curlコマンドからnodebrewをインストールする場合と少し違うようです
再構築の際にエラーなどで少しはまったので・・・
なにかおかしなところがあれば指摘していただけると幸いです。

前提条件

  • MacOS X
  • Homebrew インストール済み
  • Node.js 未インストール

nodebrewのインストール

brewコマンドを利用してnodebrewをインストール
$ brew install nodebrew

インストールの確認

$ nodebrew help
nodebrew 0.9.6

Usage:
    nodebrew help                         Show this message
    nodebrew install <version>            Download and install <version> (compile from source)
    nodebrew install-binary <version>     Download and install <version> (binary file)
    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 from binary
    nodebrew install-binary v0.10.22

    # use a specific version number
    nodebrew use v0.10.22

    # io.js
    nodebrew install-binary io@v1.0.0
    nodebrew use io@v1.0.0

情報が表示されたらOK

nodebrewのセットアップ

Homebrewでインストールした場合はnodebrew setupコマンド実行
(セットアップしないとNode.jsインストール時にエラーが出る)

$ nodebrew setup
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew

========================================
Export a path to nodebrew:

export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================

上記が表示されればセットアップ完了
続いて

Export a path to nodebrew:

export PATH=\$HOME/.nodebrew/current/bin:$PATH

と言われているでpathの設定を行う
$ echo "export PATH=\$HOME/.nodebrew/current/bin:\$PATH" >> ~/.bash_profile

設定を再読み込み
$ source ~/.bash_profile
.bash_profileに設定を記述させていますが、環境に合わせて適切に読み替えてください。

参考

本当に正しい .bashrc と .bash_profile の使ひ分け
.bash_profileと.bashrcについて

nodebrewからNode.jsインストール

インストール方法はいくつかありますが、安定板をインストール

  • stable: 安定版
  • latest: 最新版
$ nodebrew install-binary stable
Fetching: https://nodejs.org/dist/v7.2.1/node-v7.2.1-darwin-x64.tar.gz
################################################################### 100.0%
Installed successfully

Installed successfullyが表示されればインストール完了

インストールしただけではまだ利用できないので、useコマンドで利用するバージョンの指定
下記コマンドは安定板の指定

$ nodebrew use stable
use v7.2.1

最終確認

$ node -v
v7.2.1

$ npm -v
3.10.10

バージョン情報が表示されれば全て完了

初期化

合わせて初期化を行う
$ npm init
対話型で色々と聞かれるので、とりあえず全てEnterでOK(後で編集可)
ホームディレクトリにpackage.jsonができていれば初期化完了

参考サイト

nodebrewを使ってMac OSX環境のNode.jsを管理する
NodeBrewインストール編

54
50
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
54
50