LoginSignup
1
0

More than 5 years have passed since last update.

Macに最新版node.jsのインストール[nodebrew]

Last updated at Posted at 2018-07-08

概要

Macにnode.jsをインストールした際の手順を載せます。

動作環境

  • MacOS High Sierra (バージョン10.13.4)
  • Homebrew 1.6.9

インストールの手順

  1. nodebrewのインストール
  2. ディレクトリの作成
  3. nodeのインストール
  4. PATHの設定

1. nodebrewのインストール

nodeのバージョン管理ツールであるnodebrewをインストールします。

~
$ brew install nodebrew

$ nodebrew -v
nodebrew 1.0.0

nodebrewを使えば、プロジェクトごとにnodeのバージョンを変更することができるので便利です。

2. ディレクトリの作成

ホームディレクトリ以下に、隠しファイル.nodebrew/srcを生成します。

~
mkdir -p ~/.nodebrew/src

-pオプションは、途中に現在存在していないディレクトリがある場合、そのディレクトリも生成するという意味です。

3. nodeのインストール

nodebrewを使って最新版のnodeをインスールしていきます。

~
nodebrew install-binary latest

現在インストールしたnodeの一覧です。まだ、最新版だけしかインストールしていないことがわかります。

~
$ nodebrew list
v10.6.0

current: none

最新版を使用するので、以下のようにコマンドを叩きます。

~
$ nodebrew use v10.6.0
use v10.6.0

$ nodebrew list
v10.6.0

current: v10.6.0

現在の設定で、最新版のnodeに切り替えられたことがわかります。

4. PATHの設定

~
echo 'export PATH=$PATH:/Users/***/.nodebrew/current/bin' >> ~/.bash_profile  #***にはPCのユーザー名を記入

ホームディレクトリ下の~/.bash_profileに上記の設定を書き込みます。

~
source ~/.bash_profile
$ node -v
v10.6.0

.bash_profileに書いた設定を読み込み、node最新版へ切り替えが完了しました。

1
0
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
1
0