【mac】-bash: npm: command not foundが出る時の対処方法
OS:macOS Catalina
本体:MacBook Air (Retina, 13-inch, 2019)
Firebaseの練習のためにチュートリアルを進めています。
その中で以下のコードを実行する時がありました。
1 | npm install -g firebase-tools |
実行した結果はこのページのタイトルにもなっていますが、以下のコードが出てきます。
「-bash: npm: command not found」が出る理由はnpmがセットアップされていないからです。npmはNode.jsをインストールをすることで、一緒にインストールされます。そのためエラーを解消するためにはNode.jsをセットアップしましょう
対処方法・手順
nodebrewをインストールします。
1 2 3 4 5 6 7 8 | $brew install nodebrew Updating Homebrew... ==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz ################################################################################################################ 100.0% ==> Pouring portable-ruby-2.6.3_2.yosemite.bottle.tar.gz ==> Auto-updated Homebrew! ・・・ |
nodebrewをセットアップします。
1 2 3 4 5 6 7 8 9 10 11 12 | $ nodebrew setup Fetching nodebrew... Installed nodebrew in$HOME/.nodebrew ======================================== Export a path to nodebrew: export PATH=$HOME/.nodebrew/current/bin:$PATH ======================================== $ echo '# nodebrew' >> ~/.bash_profile $ echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile |
ここまでで出来たら、ターミナルを再起動しましょう。
再起動したら以下のコマンドを実行してください。
バージョンである数字が表示されたら成功です。
1 2 | $ npm -v $ node -v |