1
0

More than 1 year has passed since last update.

Windowsでnodeを複数バージョン管理するためのnvmをインストールする

Posted at

前提

  • OSは Windows10 Pro
  • scoop導入済み
  • 詳しい説明は ないです!

目的

npmのバージョンを切り替えれる環境にしたい

とりあえずnvmインストールしてみる

scoopを使って、nvmをインストール
cmdでもPowerShellでもお好きな方で

実行

cmd
scoop install nvm

結果

cmd
C:\>scoop install nvm
Installing 'nvm' (1.1.9) [64bit] from main bucket
Loading nvm-noinstall.zip from cache
Checking hash of nvm-noinstall.zip ... ok.
Extracting nvm-noinstall.zip ... done.
Running pre_install script...
Linking ~\scoop\apps\nvm\current => ~\scoop\apps\nvm\1.1.9
Creating shim for 'nvm'.
Persisting nodejs
Persisting elevate.cmd
Persisting elevate.vbs
Persisting settings.txt
'nvm' (1.1.9) was installed successfully!
Notes
-----
You'll need to restart powershell/cmd to have it reload Environment Variables so nvm will work correctly

とりあえずヘルプ見る

C:\>nvm -h
 could not be found or does not exist. Exiting.

Running version 1.1.9.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
                                 most recent LTS 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 use "latest", "lts", or "newest".
                                 "newest" is the latest installed 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.

とりあえずバージョン指定してインストールしたい

ヘルプ見限りnvm install <version>で指定したバージョンをインストールできる

どのバージョンにする?

バージョンリストを見てみる

cmd
nvm list available

結果(エラー)

cmd
ERROR open \settings.txt: The system cannot find the file specified.

!?
\settings.txtが無いって言われた(知らんがな)

エラー対処1

公式にこんなissueがあった

読んでいくと以下の回答

Where the installed application goes... the default for this is C:\Users<yourusername>\AppData\Roaming\nvm. It should look something like this:
(Google翻訳)インストールされたアプリケーションの場所...これのデフォルトは C:\Users<yourusername>\AppData\Roaming\nvm です。 次のようになります。

scoop使ってるので、C:\Users\<yourusername>\scoop\apps\nvm\1.1.9settings.txtがあったので、
\settings.txtと言われてるからC:\にコピペ
1.1.9はインストールしたnvmのバージョン)

再実行

cmd
nvm list available

バージョンリスト結果

cmd
|   CURRENT    |     LTS      |  OLD STABLE  | OLD UNSTABLE |
|--------------|--------------|--------------|--------------|
|   18.10.0    |   16.17.1    |   0.12.18    |   0.11.16    |
|    18.9.1    |   16.17.0    |   0.12.17    |   0.11.15    |
|    18.9.0    |   16.16.0    |   0.12.16    |   0.11.14    |
|    18.8.0    |   16.15.1    |   0.12.15    |   0.11.13    |
|    18.7.0    |   16.15.0    |   0.12.14    |   0.11.12    |
|    18.6.0    |   16.14.2    |   0.12.13    |   0.11.11    |
|    18.5.0    |   16.14.1    |   0.12.12    |   0.11.10    |
|    18.4.0    |   16.14.0    |   0.12.11    |    0.11.9    |
|    18.3.0    |   16.13.2    |   0.12.10    |    0.11.8    |
|    18.2.0    |   16.13.1    |    0.12.9    |    0.11.7    |
|    18.1.0    |   16.13.0    |    0.12.8    |    0.11.6    |
|    18.0.0    |   14.20.1    |    0.12.7    |    0.11.5    |
|    17.9.1    |   14.20.0    |    0.12.6    |    0.11.4    |
|    17.9.0    |   14.19.3    |    0.12.5    |    0.11.3    |
|    17.8.0    |   14.19.2    |    0.12.4    |    0.11.2    |
|    17.7.2    |   14.19.1    |    0.12.3    |    0.11.1    |
|    17.7.1    |   14.19.0    |    0.12.2    |    0.11.0    |
|    17.7.0    |   14.18.3    |    0.12.1    |    0.9.12    |
|    17.6.0    |   14.18.2    |    0.12.0    |    0.9.11    |
|    17.5.0    |   14.18.1    |   0.10.48    |    0.9.10    |

This is a partial list. For a complete list, visit https://nodejs.org/en/download/releases

とりあえず16.17.1をインストールしてみる

とりあえずのLTS…

インストール実行

cmd
nvm install 16.17.1

インストール結果

cmd
Downloading node.js version 16.17.1 (64-bit)...
Error while creating \v16.17.1\node.zip - open \v16.17.1\node.zip: The system cannot find the path specified.
Could not download node.js v16.17.1 64-bit executable.

!?
\v16.17.1\node.zip無いって言われた(知らんがな)

エラー対処2

nvm The system cannot find the path specified.でググったら一番最初に公式のissueがあった

読んでいくとこの回答のスクショ見てるとnvm onってコマンド使ってる!?

上述のヘルプだとnvm onコマンドの説明は

Enable node.js version management.
node.jsの管理を有効にするってこと…てことはインストールしただけじゃ無効だったということか。

nvmを有効にする

cmd
nvm on

nvmを有効にする結果

cmd
nvm enabled
No versions of node.js found. Try installing the latest by typing nvm install latest

有効にはなったみたい。
node.js何も入っていないから試しに最新バージョンインストールしてみて!このコマンドだよ!的なメッセージを無視しつつ16.17.1をインストールする
(特にこだわりはない)

インストール再実行

cmd
nvm install 16.17.1

インストール再実行結果

cmd
Downloading node.js version 16.17.1 (64-bit)...
Extracting...
Complete


Installation complete. If you want to use this version, type

nvm use 16.17.1

できた!

確認

cmd
node -v

確認結果

cmd
'node' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

おいおい

対処3

管理者権限でcmd(もしくはPowerShell)を起動する ことでセットされる

利用バージョン指定
cmd
nvm use 16.17.1
利用バージョン指定結果
cmd
Now using node v16.17.1 (64-bit)

余談

  • 最新バージョンインストールは
cmd
nvm install latest
  • インストール済みのリストは
cmd
nvm list
  • 使用中のバージョン確認は
cmd
nvm current
  • offにして再度onにするとインストール済みの最新バージョンになる
1
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
1
0