LoginSignup
3
4

More than 3 years have passed since last update.

homebrewを使ったnodebrew, node, yarnのinstall 環境設定(macOS Big Sur編)

Last updated at Posted at 2021-02-18

目的

node.jsを使ったプログラムをlocal環境で動かすために、
nodebrew, node, yarnをインストールする。

インストール順:homebrew → nodebrew → node → yarn

環境

homebrew インストール済み
macOS Big Sur

macOS Big Surおける homebrewのエラー対応

早速 nodebrew をインストールしようとすると、homebrewコマンドが使えないというエラーが発生した。要は、macOS Big Surにアップグレードした関係で使えなくなった。(homebrewはインストール済み)

エラー文の内容と解決

Error: Your CLT does not support macOS.
It is either outdated or was modified.
Please update your CLT or delete it if no updates are available.
Update them from Software Update in System Preferences or run:
  softwareupdate --all --install --force

If that doesn't show you an update run:
  sudo rm -rf /Library/Developer/CommandLineTools
  sudo xcode-select --install

Alternatively, manually download them from:
  https://developer.apple.com/download/more/.

上記にも記載してあるが、sudo ~ の2文を実行することで解決ができた。

  $ sudo rm -rf /Library/Developer/CommandLineTools
  $ sudo xcode-select --install

これで、macOS Big Surにてhomebrewコマンドが実行可能になる。

nodebrewのインストールをする前の確認

nodeがすでにインストールされているかどうかを確認する。
あればアンイストール、なければnodebrewのインストールを行う。

//brewに存在するディレクトリを確認
$ brew ls  

// nodeが表示されたら、以下のコマンドでアンイストール
$ brew uninstall --force node

これでnodeを入れる準備ができた!

nodebrewのインストール

nodeの複数のバージョン管理を行う事ができる、nodebrewからインストールする。

//インストールの実行
$ brew install nodebrew

//インストールされたかどうかの確認(バージョンが確認されればOK!)
$ nodebrew -v

//環境変数を追加
$ vi ~/.bash_profile

//以下の環境変数を上記ディレクトリ内に追加
 export PATH=$HOME/.nodebrew/current/bin:$PATH

//上書き保存後、bash_proileを更新
$ source ~/.bash_profile

//設定の完了
$ nodebrew setup

nodebrew setup まで行わないと、インストールが完了されないため注意。

使うバージョンを指定してnodeをインストール

nodebrewは最新版でよいが、nodeは指定されたバージョンを確認してからインストールすることが好ましい。なぜなら、nodeは更新頻度が高いため、様々なバージョンが存在する。そのためバージョン指定をしないと、インストールに時間を要してしまうからだ。

//インストール可能なバージョンを確認
$ nodebrew ls-remote

//今回は v12.18.3を指定してインストール
$ nodebrew install-binary v12.18.3

//インストールしたバージョンを確認(currrentの確認)
$ nodebrew ls

//使用するバージョンを指定
$ nodebrew use v12.18.3

//currentで表示されるものが指定したバージョンと合っているかを確認
$ nodebrew ls

//nodeのバージョン確認
$ node -v

nodebrew ls を打つと、nodeのバージョンが複数存在する。その際は、nodebrew use vxx.xx.xのように指定することで、currentとして使うバージョン指定が可能である。

"プロジェクトによってはnpmのバージョン互換が問題になることが多いため、nodebrewを使うことで複数のプロジェクトで、別々のNodeを使い分けられるようになる点がnodebrewのメリットである"

yarnのインストール

yarnのインストールはnodeよりも簡単

//yarnのインストール
$ brew install yarn

//yarnのバージョン確認
$ yarn --version

yarnのバージョンが確認できれば問題なし!

以上

参考記事

Homebrewで「Your CLT does not support macOS 11」エラーの対応
nodebrewでNode.jsをインストールする。
Mac: yarn install
NodebrewでNodeをインストールする

3
4
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
4