LoginSignup
13
12

More than 5 years have passed since last update.

《Node.js》nodebrewでnode.jsのバージョン管理をする

Last updated at Posted at 2017-10-27

node.jsのバージョン管理(切り替え)をするために、nodebrewを導入します。

6系, 8系 とプロジェクトやタスクやお試しで、切り替える必要がある時の話で、
この環境は OSX 10.11.6 ということで進めていきます。

node.jsをすでにパッケージでインストールしている場合は、

これでアンインストールします。

nodebrewをインストールするためにHomebrewをインストール

Homebrewを導入していない場合は、まずHomebrewをインストールします。

nodebrewをインストール


brew install nodebrew

エラーするとき

ちょうどぼくの環境だと、インストールしようとしたら、以下のエラーが出ました。


Please delete these paths and run `brew update`.

というわけで、いらないものを削除して、アップデートします。


rm -rf /usr/local/share/doc/homebrew

そして、


brew update

これで解決しました。

nodebrewのセットアップ


nodebrew setup

Node.jsをインストール

インストール可能なNode.jsのバージョン一覧を見てみます。


nodebrew ls-remote

目標を確認できたらインストールします。


nodebrew install-binary [version]

インストールしたものを確認します。


nodebrew ls

最新版をインストールするには、


nodebrew install-binary latest

安定版をインストールするには、


nodebrew install-binary stable

使用するバージョンを指定する

幾つかのバージョンをインストールしたら、使用するバージョンを指定します。


nodebrew use [version]

pathを通す

pathを通さないとnodeコマンドが実行できません。

~/.bash_profile に記述します。


echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile

そして再読み込みさせます。


source ~/.bash_profile

すると、 node -v などなどの nodeコマンドを使うことができるようになります。

その他

アンインストール

不要なnode.jsのversionは削除しましょう。


nodebrew uninstall [version]

ついでにyarnもインストール


brew install yarn

IDEに注意される

ぼくはWebStormを使っているのですが、node.jsへのパスが変わってしまったので警告されました。パスを通すことをアシストしてくれるので、設定し直します。または、環境設定から、node.jsと検索すると、パスを通す画面に移行するので、そこから設定しておきます。

おわります。

13
12
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
13
12