首頁·終端機命令

nvm use

套件與執行環境

用法

nvm use <version> | nvm use --lts

切換目前 shell 使用的已安裝 Node 版本;改動只作用於這個 shell,新開的終端機或 CI 會回到預設值,而 nvm 是個 shell 函式,指令稿或 Makefile 裡得先 source nvm.sh。

常用選項

選項含義
--ltsthe newest long-term-support line you have installed
nvm install <version>download it first; use only switches to installed ones
nvm alias default <version>what a brand-new shell should start with
nvm lsthe versions on this machine
nvm currentwhich one is active in this shell

範例

nvm use 22

switches this shell to node 22

nvm use --lts

switches to the newest installed LTS

nvm alias default 22

so new terminals and editors also get 22

問題永遠是什麼裝到哪裡:裝進這個專案,還是裝到整台機器上。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. nvm use 是做什麼的?

切換目前 shell 使用的已安裝 Node 版本;改動只作用於這個 shell,新開的終端機或 CI 會回到預設值,而 nvm 是個 shell 函式,指令稿或 Makefile 裡得先 source nvm.sh。

Q. 怎麼寫?

nvm use <version> | nvm use --lts —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 5 個,完整列表在 man nvm。這條命令屬於套件與執行環境。

相關命令

man 手冊: man nvm-use