LoginSignup
0
0

More than 1 year has passed since last update.

[黙示録] Macでnodebrew を使ってnode.jsをインストールする方法

Last updated at Posted at 2022-07-05

Javascriptの勉強を始めて1ヶ月。
node.jsをようやくインストールしたので、自分のインストール手順を忘れないためにも記事に残しておきます。

環境

  • Homebrew 3.5.3
  • MacOS Monterey 12.4

nodebrewのインストール

brewコマンドでインストールをしていきます

コマンド
brew install nodebrew

以下のようなメッセージが表示されたので、メッセージ通りの初期設定を行っていきます。

結果
You need to manually run setup_dirs to create directories required by nodebrew:
  /usr/local/opt/nodebrew/bin/nodebrew setup_dirs

Add path:
  export PATH=$HOME/.nodebrew/current/bin:$PATH

To use Homebrew's directories rather than ~/.nodebrew add to your profile:
  export NODEBREW_ROOT=/usr/local/var/nodebrew

コマンド
/usr/local/opt/nodebrew/bin/nodebrew setup_dirs
コマンド
open ~/.bash_profile
.bash_profile
export PATH=$HOME/.nodebrew/current/bin:$PATH
export NODEBREW_ROOT=/usr/local/var/nodebrew

正しくPATHが通っていれば、以下のようにnodebrewが使えるようになっています。

コマンド
$ nodebrew help
nodebrew 1.2.0

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 backward 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>
    nodebrew prune [--dry-run]            Uninstall old versions, keeping the latest version for each major version

Example:
    # install
    nodebrew install v8.9.4

    # use a specific version number
    nodebrew use v8.9.4
 

node.jsのインストール

  • インストールできるバージョンを確認します
コマンド
$  nodebrew ls-all
remote:
v0.0.1    v0.0.2    v0.0.3    v0.0.4    v0.0.5    v0.0.6    

v0.1.0    v0.1.1    v0.1.2    v0.1.3    v0.1.4    v0.1.5    v0.1.6    v0.1.7
v0.1.8    v0.1.9    v0.1.10   v0.1.11   v0.1.12   v0.1.13   v0.1.14   v0.1.15
v0.1.16   v0.1.17   v0.1.18   v0.1.19   v0.1.20   v0.1.21   v0.1.22   v0.1.23
  
<省略>

local:
not installed

current: none

今回は安定板をインストールしたいので、

コマンド
nodebrew install-binary stable

上記のコードを実行します。

結果
Fetching: https://nodejs.org/dist/v18.4.0/node-v18.4.0-darwin-x64.tar.gz
################################################################################################################################################################################################### 100.0%
Installed successfully

2022年7月現在では、v18.4.0がインストールされるみたいです。

nodeの有効化

現状このままでは、まだnodeは使えません。

コマンド
$ node -v
-bash: node: command not found

利用するには、nodebrew useでインストールしたバージョンのnode.jsを有効化してあげます。

コマンド
nodebrew use v18.4.0

これでようやくnodeが使える!と思っていたら、、、

コマンド
$ node -v
-bash: node: command not found

色々試したところ、以下のコードを実行し、記載されたPATHを通すことで実行できました。

コマンド
$ nodebrew setup
Fetching nodebrew...
Installed nodebrew in /usr/local/var/nodebrew

========================================
Export a path to nodebrew:

export PATH=/usr/local/var/nodebrew/current/bin:$PATH
========================================


$ open ~/.bash_profile
$ node -v
v18.4.0

参考

0
0
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
0
0