Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8691

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

$
0
0

参考記事

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

目的

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

インストール順:homebrew(今回は省略) → nodebrew → node → yarn

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として使うバージョン指定が可能である。

yarnのインストール

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

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

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

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

以上


Viewing all articles
Browse latest Browse all 8691

Trending Articles