MacにHomebrew、Nodebrew、Node.jsをインストールしてみた

node js fs

今更ですが、node-sassを試してみたいなと思いhomebrew、nodebrew、node.jsをインストールすることに

Homebrewのインストール

公式サイトにアクセスして、インストールのスクリプトを実行すると完了

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

インストールが終わったら、バージョンを確認

$ brew -v

「公式サイト」
https://brew.sh/index_ja.html

Nodebrewのインストール

Homebrewを使ってインストールして、バージョンを確認

$ brew install nodebrew
$ nodebrew -v

Node.jsのインストール

nodebrewのコマンドで設置可能なバージョンを確認する

$ nodebrew ls-remote

下記のコマンドで最新をインストール

$ nodebrew install-binary latest

しようとしたら、必要なディレクトリーがないとエラーを吐く
エラーを取っておらず、同じエラーを見つけて記載した。

Fetching: https://nodejs.org/dist/v7.10.0/node-v7.10.0-darwin-x64.tar.gz
Warning: Failed to create the file
Warning: /Users/whoami/.nodebrew/src/v7.10.0/node-v7.10.0-darwin-x64.ta
Warning: r.gz: No such file or directory
curl: (23) Failed writing body (0 != 941)
download failed: https://nodejs.org/dist/v7.10.0/node-v7.10.0-darwin-x64.tar.gz

ディレクトリーを作成して再度インストールを行うと無事完了

$ mkdir -p ~/.nodebrew/src

インストールしただけでは、まだnode.jsが有効になってないので設定を変更する必要がある。

$ nodebrew ls
v12.12.0
current: none
$ nodebrew use v12.12.0
$ nodebrew ls
v12.12.0
current: v12.12.0

nodeを使えるように環境パスの設定

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

パスの設定が終わったら、ターミナルの再起動が必要だった。

もし、上記の設定でもパスが通ってないなら.bash_profileに下記のコードを追記してみる

$ vi ~/.bash_profile
export PATH=$PATH:$HOME/.nodebrew/current/bin
if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi
~

次のPC再起動からこれが実行されるのですが、今すぐこのスクリプトを実行したい時は以下のコマンドです。

$ source ~/.bash_profile

nodeの確認

$ node -v 

おわり〜

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です