nvm icon indicating copy to clipboard operation
nvm copied to clipboard

[Feature request] flag for `nvm use` that says "install it if you don't have it"

Open TimothyJones opened this issue 3 years ago • 1 comments

First off, thanks for this absolutely excellent tool! Much appreciated.

In nvm v0.39.1 (the latest at the time of writing), when I do nvm use for a version I don't have yet, I get a prompt to run nvm install:

$ nvm use

Found '/Users/tim/example/.nvmrc' with version <14.17.6>
N/A: version "14.17.6 -> N/A" is not yet installed.

You need to run "nvm install 14.17.6" to install it before using it.

It would be awesome if I could do something like:

$ nvm use --install-if-not-present
Found '/Users/tim/example/.nvmrc' with version <14.17.6>
N/A: version "14.17.6 -> N/A" is not yet installed.

Downloading and installing node v14.17.6...
...etc

(I don't know that --install-if-not-present is the best name for this flag, I just wanted to make the intent clear in this request)

nvm install does seem to also imply nvm use (although I haven't seen this documented). However, it takes several seconds even when you already have the version installed, whereas nvm use is immediate when I already have the version installed. If the intended solution is to use nvm install for this use case, then I'm happy to open an issue about the slow timing of nvm install instead.

TimothyJones avatar Jun 07 '22 06:06 TimothyJones

This is the behavior nvm install already has, yes, and is the intended usage.

#2827 may improve perf here, but if not, please do file a new issue.

ljharb avatar Jun 07 '22 12:06 ljharb