3
1

More than 3 years have passed since last update.

Node.jsのインストール

Posted at

概要

  • MacにNode.jsをインストールする。
  • ターミナルでHomebrewを使ってインストールする。

前提

  • Homebrewをインストール済
  • ログインシェルがzsh

手順

  1. nodebrewをインストールする
  2. Node.jsをインストールする
  3. パスを通す

1. nodebrewをインストールする

下記を実行する

terminal
brew install nodebrew

※補足:nodebrewのバージョン確認

terminal
nodebrew -v

2. Node.jsをインストールする

2.1 nodebrewでNode.js(安定版)をインストールする

下記を実行する

terminal
nodebrew install-binary stable

※補足:下記のような結果が出て、インストールができなかった場合

terminal(結果)
Fetching: https://nodejs.org/dist/v14.14.0/node-v14.14.0-darwin-x64.tar.gz
Warning: Failed to create the file
Warning: /Users/[username]/.nodebrew/src/v14.14.0/node-v14.14.0-darwin-x64.tar
Warning: .gz: No such file or directory

curl: (23) Failed writing body (0 != 980)
download failed: https://nodejs.org/dist/v14.14.0/node-v14.14.0-darwin-x64.tar.gz

下記を実行する(.nodebrewディレクトリがない場合、-pオプションをつける)

terminal
mkdir -p ~/.nodebrew/src

その後、再度2.1を実行

2.2 インストールしたバージョンを使用するようにする

2.2.1 インストールしたバージョンを確認する

下記を実行する

terminal
nodebrew ls
terminal(結果)
v14.14.0

current: none

※「current: none」は、現在使用に指定しているバージョンはないという意味

2.2.2 インストールしたバージョンを使用するようにする

下記を実行する

terminal
nodebrew use v14.14.0

再度下記を実行

terminal
nodebrew ls

下記の通り、インストールしたバージョンが使用に指定されていることを確認

terminal(結果)
v14.14.0

current: v14.14.0

3. パスを通す

3.1 Node.jsを使えるように、下記を実行しパスを通す

terminal
echo "export PATH=$HOME/.nodebrew/current/bin:$PATH" >> ~/.zshrc

下記を実行し、ファイルを読み直す

terminal
source ~/.zshrc

3.2 使用可能かを確認する

下記を実行する

terminal
node -v

下記のような結果が出れば完了

terminal(結果)
v14.14.0
3
1
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
3
1