2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

nodebrewでNode.jsバージョンをプロジェクトごとに管理する

Last updated at Posted at 2023-05-12

nodebrewとは

  • nodebrewは、一つのマシン上で複数のバージョンのNode.jsを管理するためのツール。
  • 開発するプロジェクトごとに利用するNode.jsのバージョンが異なる場合などに便利。

環境

  • Mac OS
  • Homebrew
  • nodebrew
  • bash

nodebrew公式

全ての手順はここに書かれてるので、詳しくは参照してください。

手順

こんな順番で進めます。

  • Homebrewを使ってnodebrewをインストールする
  • 環境変数PATHを通してから有効にする
  • nodebrewを使って特定のバージョンのNode.jsをインストールする
  • プロジェクトのルートディレクトリに移動する
  • 使用するNode.jsのバージョンを切り替える

作業開始!

Homebrewを使ってnodebrewをインストールする

Homebrewでnodebrewを管理したいので今回はそうします。

Homebrewを使ってnodebrewをインストールする
$ brew install nodebrew

環境変数PATHを通してから有効にする

PATHを通す ※bashにパスを通す場合
$ echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> .bash_profile
$ source ~/.bash_profile # bash_profileの再読み込みで有効にする

nodebrewを使って特定のバージョンのNode.jsをインストールします。

nodeをバージョン指定でインストール
$ nodebrew install 18.16.0
nodeインストールバージョンのリスト表示
$ nodebrew ls
v6.11.4
v12.4.0
v12.6.0
v14.15.0
v18.16.0

current: v14.15.0  # (v14.15.0を使用中)

プロジェクトのルートディレクトリに移動する

nodeバージョン切替え、バージョン確認
$ cd [YourProject]

使用するNode.jsのバージョンを切り替える

nodeバージョン切替え、バージョン確認
$ nodebrew use 18.16.0
$ node -v
v18.16.0

以上

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?