Node.js のバージョン管理ツールに nvm を使っていましたが、 Volta というものがあるのを知ったので使ってみました。
Volta とは
ドキュメントには以下の記載があります。 JavaScript コマンドライン ツール (node、npm、yarn、JavaScript パッケージの一部に含まれる実行可能ファイルなど) を管理すること、とのことです。
-
Understanding Volta Volta’s job is to manage your JavaScript command-line tools, such as node, npm, yarn, or executables shipped as part of JavaScript packages.
Similar to package managers, Volta keeps track of which project (if any) you’re working on based on your current directory. The tools in your Volta toolchain automatically detect when you’re in a project that’s using a particular version of the tools, and take care of routing to the right version of the tools for you.
-
Volta does not use any fancy OS features or shell-specific hooks. It’s built on the simple, proven approach of shims.
Whenever you install a tool with Volta, it adds a shim to your PATH that acts as an intelligent (and fast) router to the right version of the tool and runs it with the right Node engine.
Volta is easy to install, with no external dependencies, because it’s built in Rust as a single, fast native executable.
Rust で記述されているようです。
Volta インストール
Linux や macOS では以下でインストールできます。
% curl https://get.volta.sh | bash
以下の環境変数を設定します。 ~/.zshrc などに設定する場合は、記述後にシェルを再読み込みします。
% export VOLTA_HOME=$HOME/.volta % export PATH=$VOLTA_HOME/bin:$PATH
コマンドが実行可能になります。
% volta --version 2.0.2
Node.js のインストール
Node.js をインストールします。
% volta install node@22 success: installed and set node@22.13.0 (with npm@10.9.2) as default
$HOME/.volta/bin/node にコマンドが配置されています。
% which node /home/dshimizu/.volta/bin/node
% node -v v22.13.0
volta list をみてみます。
% volta list
⚡️ Currently active tools:
Node: v22.13.0 (default)
Tool binaries available: NONE
See options for more detailed reports by running `volta list --help`.
Node v20系をインストールしてみます。
% volta install node@20 success: installed and set node@20.18.1 (with npm@10.8.2) as default
Node v20 がデフォルトになりました。
2025/01/19 14:14:30 ~ % node -v v20.18.1
volta list をみてみます。
% volta list
⚡️ Currently active tools:
Node: v20.18.1 (default)
Tool binaries available: NONE
See options for more detailed reports by running `volta list --help`.
volta list all を実行すると全ての Node バージョンが出力されます。
% volta list all
⚡️ User toolchain:
Node runtimes:
v20.18.1 (default)
v22.13.0
Package managers:
Packages:
Node v22.13.0 にするには volta install を使うようです。
% volta install node@22.13.0 success: installed and set node@22.13.0 (with npm@10.9.2) as default
変わりました。
% volta list all
⚡️ User toolchain:
Node runtimes:
v20.18.1
v22.13.0 (default)
Package managers:
Packages:
おわりに
JavaScript コマンドラインツールを管理する Volta を Debian 12 へインストールして使ってみました。 特にフロントエンドを触ったりしないのでコマンド体系を覚えるのに時間がかかりそうですが、しばらく触ってみます。