Windows10にNode.jsをインストールする方法をご紹介します。
Node.jsをそのままインストールすることも出来るのですが、Node.jsのバージョンアップは非常に頻繁なため、最新版をインストールしたり、開発時に使用するバージョンに切り替えたりするのが大変です。Node.js管理ツールでNode.jsを管理することでこの課題をクリアします。
Node.js管理ツールインストール
Node.jsを管理するツールとして様々なものがあります。Windowsに対応した有名なものだとnodist、nvm-windows、Voltaなどがあります。nodistは2022年1月5日時点での最終更新が2019年になっており、しばらくアップデートかかっていません。nvm-windowsは最近でも更新が行われており、Microsoft公式サイトでもダウンロード方法が紹介されています。そのため、私はnvm-windowsを選択しました。
あとから気付いたのですが、nvm-windowsはNode.jsのバージョン自動切換えに対応していません。画面操作は非常にわかりやすくて良いのですが。その影響か、最近ではVoltaをおススメしているサイトをよく見かけます。
nvm-windowsを公式サイトからダウンロードしてインストールします。GUIがついていますので簡単にインストールできました。簡単なコマンドでNode.jsもインストールすることが出来ました。
設定確認
次にきちんと意図したとおりにインストールされたか、設定の確認をします。nvm-windowsがインストールされているか、Node.jsがインストールされているかは次のように確認できます。
nvm-windowsがインストールされているか
コマンドプロンプトで次のコマンドを実行して確認します。
>nvm Running version 1.1.7. Usage: nvm arch : Show if node is running in 32 or 64 bit mode. nvm install <version> [arch] : The version can be a node.js version or "latest" for the latest stable version. Optionally specify whether to install the 32 or 64 bit version (defaults to system arch). Set [arch] to "all" to install 32 AND 64 bit versions. Add --insecure to the end of this command to bypass SSL validation of the remote download server. nvm list [available] : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls. nvm on : Enable node.js version management. nvm off : Disable node.js version management. nvm proxy [url] : Set a proxy to use for downloads. Leave [url] blank to see the current proxy. Set [url] to "none" to remove the proxy. nvm node_mirror [url] : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url. nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url. nvm uninstall <version> : The version must be a specific version. nvm use [version] [arch] : Switch to use the specified version. Optionally specify 32/64bit architecture. nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode. nvm root [path] : Set the directory where nvm should store different versions of node.js. If <path> is not set, the current root will be displayed. nvm version : Displays the current running version of nvm for Windows. Aliased as v.
Node.jsがインストールされているか
コマンドプロンプトで次のコマンドを実行して確認します。
>node -v v13.7.0
これでnvm-windows、Node.jsともにインストール出来ました。