LoginSignup
37
19

More than 3 years have passed since last update.

【Catalina】nodebrewからnode, yarnをインストール

Posted at

はじめに

node.jsのバージョン管理とyarnのインストールについて
色々な所からインストールしていたら、brew doctorから怒られてしまいました。。。
Catalinaにアップデートしたら、読み込めないし、、、

$ node -v
zsh: node: command not found

PATHを通すと node -v, npm -v が使えるようですが

せっかくなので、一元管理するため
一度、全てアンインストールしてから再インストールしました。
nodebrewでの管理が上手くいったので、自分用メモとして残しておきます。

nodeの管理はnodebrewで行い、npmからyarnをインストールしました。
※公式では非推奨らしいですが、、、
https://yarnpkg.com/ja/docs/install#alternatives-stable

node.jsとyarnの削除

今まで入れていたnodeとyarnを全て削除します。

(例)Homebrewで入れた場合
$ brew uninstall yarn
$ brew uninstall node
$ rm -rf /usr/local/lib/node_modules
$ brew cleanup
念のため
$ brew doctor

アンインストール後にPATHが変更されているので .bash_profile の再読み込み。

$ source ~/.bash_profile 

nodebrew のインストール

Homebrew から nodebrew をインストール
$ brew install nodebrew
バージョンを確認
$ nodebrew -v

実行結果

nodebrew 1.0.1

Usage:
    nodebrew help                         Show this message
    nodebrew install <version>            Download and install <version> (from binary)
    nodebrew compile <version>            Download and install <version> (from source)
    nodebrew install-binary <version>     Alias of `install` (For backword compatibility)
    nodebrew uninstall <version>          Uninstall <version>
    nodebrew use <version>                Use <version>
    nodebrew list                         List installed versions
    nodebrew ls                           Alias for `list`
    nodebrew ls-remote                    List remote versions
    nodebrew ls-all                       List remote and installed versions
    nodebrew alias <key> <value>          Set alias
    nodebrew unalias <key>                Remove alias
    nodebrew clean <version> | all        Remove source file
    nodebrew selfupdate                   Update nodebrew
    nodebrew migrate-package <version>    Install global NPM packages contained in <version> to current version
    nodebrew exec <version> -- <command>  Execute <command> using specified <version>

Example:
    # install
    nodebrew install v8.9.4

    # use a specific version number
    nodebrew use v8.9.4

nodebrew の PATH を通す

.bash_profile から .zprofile へお引っ越し
$ cat .bash_profile >> .zprofile

.zprofile にPATHを追加
$ echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.zprofile

.zprofile を再読み込み。
$ source ~/.zprofile

安定版の Node.js をインストール

$ nodebrew install-binary stable

ディレクトリが見つからない場合は、作成

$ mkdir -p ~/.nodebrew/src
$ nodebrew install-binary stable

Node.jsを設定します。

利用可能バージョンを確認
$ nodebrew list

current: noneなので、バージョンを指定
$ nodebrew use v12.14.0

Node.js のバージョンを確認
$ node -v

yarnをインストール

$ npm install -g yarn
$ yarn -v
バージョンが表示されれば OK
37
19
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
37
19