LoginSignup
1
2

More than 3 years have passed since last update.

Node.jsのバージョン管理システム「nodebrew」を使ってNode.jsをインストールする手順

Last updated at Posted at 2020-04-09

はじめに

nodebrewはNode.jsのバージョンを管理するためのツールです。
nodebrewを使うことで、一つの環境に複数バージョンのNode.jsを導入することができ、バージョンの切替も簡単に行えます。

環境

OS:macOS Catalina v10.15.3

nodebrewのインストール

nodebrewのGitHubに手順が記載されていますので、そちらを参考にインストールしていきます。
https://github.com/hokaccha/nodebrew

curlでインストールします。
※今回はcurlでインストールしましたがmacOS用パッケージマネージャ「Homebrew」からのインストールをお勧めします

$ curl -L git.io/nodebrew | perl - setup
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
100 24634  100 24634    0     0   9763      0  0:00:02  0:00:02 --:--:--  9763
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew

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

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

パスを通します。

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

インストール後の確認。nodebrewコマンドが認識されていればOKです。

$ nodebrew help
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 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>

Example:
    # install
    nodebrew install v8.9.4

    # use a specific version number
    nodebrew use v8.9.4

Node.jsのインストール

今回は最新バージョンのNode.jsをインストール。

$ nodebrew install latest
Fetching: https://nodejs.org/dist/v13.12.0/node-v13.12.0-darwin-x64.tar.gz
######################################################################################## 100.0%
Installed successfully

インストールされたNode.jsのバージョンを一覧で表示する。
(複数バージョンがインストールされている場合は複数行表示されます)

$ nodebrew ls
v13.12.0

使用するバージョンを設定する。

$ nodebrew use v13.12.0
use v13.12.0

もう一度インストールされたNode.jsのバージョンを一覧で表示する。
currentが表示され、現在選択されているNode.jsのバージョンが確認できます。

$ nodebrew ls
v13.12.0

current: v13.12.0

nodeコマンドを実行してバージョンを確認すると適用したバージョンになっています。

$ node -v
v13.12.0

最後に

複数プロジェクトで違うバージョンのNode.jsを使っているとバージョン管理が面倒ですが、nodebrewを導入するとコマンド一つでバージョン管理ができるのでめちゃくちゃ楽です。

1
2
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
1
2