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 で指定された Node.js バージョンに nodenv で切り替える手順まとめ【初心者向け】

Posted at

はじめに

新規プロジェクトに .node-version ファイルがあるけど、「これどうやって使うの?」と思ったことはありませんか?

この記事では、Node.jsのバージョンを nodenv でプロジェクトごとに切り替える方法を、初心者向けに解説します!

使用環境

・OS:macOS(Intel / Apple Silicon 両対応)

・バージョンマネージャー:nodenv

1. .node-version ファイルとは?

Node.js のバージョンをプロジェクトごとに固定するための設定ファイルです。
このファイルを使うことで、複数のプロジェクトを異なるNodeバージョンで安全に管理できます。

2. nodenvのインストール手順

brew install nodenv
# シェルにパスを通す
echo 'export PATH="$HOME/.nodenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(nodenv init -)"' >> ~/.zshrc
source ~/.zshrc

インストール後はシェルを再起動する!

3. .node-version を確認して、バージョンをインストール

cat .node-version
# 例:18.16.1

nodenv install 18.16.1

4. 使用バージョンをプロジェクトに設定

nodenv local 18.16.1

.node-version がプロジェクトに置かれ、自動的に切り替わるようになります。

5. バージョン確認

node -v
# v18.16.1 が表示されればOK!

おわりに

チーム開発や複数のプロジェクトを扱う際、Node.jsのバージョンがズレていると予期せぬエラーの元になります。
nodenv.node-version をうまく使って、安定した開発環境を保ちましょう!

✨ Tips

Windows の場合は nodist など他のマネージャーが使われることもあります

Node.js をバージョン切り替えできるようになると、複数プロジェクトでの開発が快適になります

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?