nvm use: Usage, Options & Common CI Errors
nvm use switches which installed Node.js version is active in the current shell.
nvm use selects an already-installed Node version for the current shell session. In CI the trap is that each step is a fresh shell, so a selection in one step does not carry to the next.
What it does
nvm use <version> points node/npm at an installed version by adjusting PATH in the current shell. It only affects that shell - it does not persist across steps or jobs. nvm use with no argument reads .nvmrc. The version must already be installed (nvm install) or nvm use errors.
Common usage
. "$NVM_DIR/nvm.sh" # source nvm in this shell
nvm use 20
nvm use # use the .nvmrc version
nvm use --lts
nvm alias default 20 # make 20 the default shell versionCommon errors in CI
"N/A: version \"20\" is not yet installed. You need to run \"nvm install 20\"" - nvm use only selects installed versions. The subtler failure: nvm use in step A, then step B still runs the system node - because each CI step is a new shell that did not source nvm or call nvm use. Either set a default (nvm alias default <v>) and re-source nvm per step, or pin Node via the platform's setup-node action. ".nvmrc" with a bare version line is required for nvm use with no arg.
Options
| Item | What it does |
|---|---|
| <version> | Switch to an installed version |
| (no arg) | Use the version in .nvmrc |
| --lts | Use the latest installed LTS |
| alias default <v> | Set the default version for new shells |