0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

.node-versionとnodenvでNode.jsのバージョン管理をする

Posted at

もともとはnodebrewがインストールしてあったのだが、プロジェクトによってnodeのバージョンが違かったため不便だった。
.node-versionに記載してあるnodeのバージョンによってnodeを使い分けたいときにはnodenvを使用すると良さそう。

nodenvのインストールと設定

nodenvをHomebrewでインストール

$ brew install nodenv

少し時間がかかるが待つ。

$ nodenv -v
nodenv 1.5.0

nodenvのバージョンが表示される。これでnodevnはインストールできた。

シェル設定に追加

※ MacOS、zshrcの場合

$ echo 'eval "$(nodenv init -)"' >> ~/.zshrc

$ source ~/.zshrc

これで.node-versionに記載してあるバージョン番号を認識してくれる。

$ node -v

意図したnodeのバージョンが表示されることを確認しよう。

nodenvの使い方

nodeのインストール

$ nodenv install 22.0.0

これでnode22をインストールする。

ディレクトリで使用したnodeのバージョンを指定する

$ nodenv local 22.0.0

プロジェクトのディレクトリで使用するバージョンを指定する。
これにより.node-versionが自動的に作成もしくは更新される。

$ node -v
v22.0.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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?