Files
hollywood/02-code/nvm_core_cmds.md
T

44 lines
2.2 KiB
Markdown

---
tags:
- nvm
- cmds
---
**Core commands:**
```powershell
nvm list # installed versions
nvm list available # versions you can install
nvm install <version> # e.g. nvm install 20.18.0
nvm use <version> # switch active version
nvm uninstall <version> # remove one
```
**Practical stuff you'll actually hit:**
1. **`nvm use` is per-shell, not per-project.** Every new terminal window defaults back to whatever was last set globally — it does NOT auto-detect per-folder like nvm on Mac/Linux does. nvm-windows has no built-in `.nvmrc` autoswitch.
2. **Fake it with `.nvmrc` + a wrapper function.** Add this to your PowerShell `$PROFILE` to auto-switch when you `cd` into a folder with a `.nvmrc`:
```powershell
function nvmrc-check {
if (Test-Path .nvmrc) {
$version = Get-Content .nvmrc -Raw
nvm use $version.Trim()
}
}
```
You'd need to hook this to directory changes yourself (no native hook in PowerShell) — or just manually run `nvm use` when you switch projects. Not worth automating unless you're juggling many projects daily.
3. **Global npm packages don't carry over between Node versions.** Installing `npm i -g something` under 24.18.1 means it's gone if you `nvm use 20.x`. Reinstall globals per version you actually use.
4. **`nvm use` requires admin the FIRST time after a fresh nvm-windows install**, then not after — it's flipping a symlink at `C:\Program Files\nodejs`. If PowerShell isn't elevated the first time, you'll get silent permission failures. You already got it working, so this is a non-issue now, but keep it in mind after Windows updates or profile changes.
5. **Check `npm config get prefix`** — with nvm-windows this should point to the nvm symlink path, not a per-user AppData path. If a global tool ever "disappears" after switching versions, that's why — it's expected, not broken.
6. **LTS vs current:** `nvm install lts` grabs whatever's tagged LTS at install time — it does NOT auto-update to newer LTS releases later. You'll need to rerun `nvm install lts` periodically and `nvm use` the new one.
That covers what actually bites people. Anything specific you're about to do with it (global CLI tools, multiple project versions, etc.) — I can give exact commands.