Javascript(Node.js) 開発環境の構築
Javascript(Node.js) 開発環境の構築
Node.js のインストール mac編
mac へのインストールについて
noode.js をインストールするにあたり、node.js のバージョン管理ツールの nodebrew をインストールして管理をしておくと、バージョンアップや複数バージョンの環境を自端末に残しておくと気に便利となります。 特にそういった要件がない方は、node.js のサイトにインストーラがありますので、それをインストールすれば動作環境は構築できます。
Node.js サイト 2016年1月 現在では、v7.4.0 が最新の安定版
https://nodejs.org/ja/
nodebrew を利用した Node.js のインストール
Homebrewのインストール、CommandlineTools のインストール、nodebrew のインストールの順に進めます。
Homebrew のインストール
下記URLを開きインストールコマンドをコピーする
http://brew.sh/index_ja.html
2016/1/24 時点の掲載コマンド
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
CommandlineTools も同時にインストールされるが、もしそこでエラーが出る場合は、CommandlineTools を先にインストールする。
CommandlineTools は下記URLからダウンロード可能
https://developer.apple.com/downloads/index.action
brew -v でバージョンを確認
~ $ brew -v Homebrew 1.1.8 Homebrew/homebrew-core (git revision 3605; last commit 2017-01-23)
brew doctor で正常にインストールされているか確認
~ $ brew doctor Your system is ready to brew.
Homebrew を利用してnodebrewをインストール
brew install nodebrew でインストールされる
~ $ brew install nodebrew ==> Using the sandbox ==> Downloading https://github.com/hokaccha/nodebrew/archive/v0.9.6.tar.gz ==> Downloading from https://codeload.github.com/hokaccha/nodebrew/tar.gz/v0.9.6 ######################################################################## 100.0% ==> /usr/local/Cellar/nodebrew/0.9.6/bin/nodebrew setup_dirs ==> Caveats Add path: export PATH=$HOME/.nodebrew/current/bin:$PATH To use Homebrew's directories rather than ~/.nodebrew add to your profile: export NODEBREW_ROOT=/usr/local/var/nodebrew Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completion has been installed to: /usr/local/share/zsh/site-functions ==> Summary 🍺 /usr/local/Cellar/nodebrew/0.9.6: 8 files, 38.0K, built in 8 seconds
nodebrew -v コマンドでバージョンの確認
~ $ nodebrew -v nodebrew 0.9.6
nodebrew を利用して Node.js をインストール
nodebrew install-binary stable
下記のエラーとなった場合は、ディレクトリを作成する
Warning: Failed to create the file Warning: /Users/fujimori/.nodebrew/src/v7.4.0/node-v7.4.0-darwin-x64.tar.gz: Warning: No such file or directory
nodebrewが利用するディレクトリの作成
mkdir ~/.nodebrew mkdir ~/.nodebrew/src
~ $ nodebrew install-binary stable Fetching: https://nodejs.org/dist/v7.4.0/node-v7.4.0-darwin-x64.tar.gz ######################################################################## 100.0% Installed successfully ~ $ nodebrew ls v7.4.0
PATH を通す(.bash_profileの追加)
export PATH=$HOME/.nodebrew/current/bin:$PATH
利用するバージョのを指定する
nodebrew use v7.4.0
v7.4.0 が利用可能になった
~ $ nodebrew ls v7.4.0 current: v7.4.0