Would it be possible to add something like nvm upgrade? I imagine it would upgrade to the latest minor/patch version of the currently active version (or just latest patch for v0.x), and would be functionally equivalent to something like nvm install [major version] --reinstall-packages-from=$(nvm version). There could also be an optional switch to delete the old version.
I've been using this in my profile, which isn't quite as nice as I have to specify the new version to install:
# nvm-upgrade NEW_VERSION
#
# Installs the specified version of node via nvm, reinstalling all global
# packages from the currently activated version of node. Does not delete
# the previous node version.
function nvm-upgrade() {
nvm install $1 --reinstall-packages-from=`nvm version`
nvm use $1
npm install -g npm
npm upgrade -g
}
The primary use case for nvm isn't "i have one version of node and i'm using nvm to manage it".
nvm alias default node and nvm install node --reinstall-packages-from=node is usually sufficient.
I'll leave this open, but a feature like this necessitates many assumptions about the user's use cases and environment that I don't think will be worth it.
On the contrary, I have several versions of node installed, but I really only need 0.10.x, 0.12.x, 4.3.2 (thanks Lambda), and 5.x. It's not a huge problem, but would just be a nice feature to have (and to be able to instruct my less conscientious colleagues to use)
Makes sense. It's not an unreasonable request at all, I'm just not yet convinced the cost/benefit of the complexity is worth it :-)
Gotcha, that's fair. My shell scripting knowledge isn't perfect, but I'll see if I can come up with a viable PR
@spencerhakim
I think you shouldn't do this:
npm install -g npm
npm upgrade -g
Because it's hard to manage versions when there is a step that installs something unpredictable (last npm version? last version of npm dependencies?).
I think this specific behavior will not land on nvm code base.
I know that it's just a copy and paste of what you are doing on your environment, but I'm taking the opportunity to recommend you to always choose reproducible environment over last packages versions as much as possible.
I definitely wouldn't add npm upgrade -g or anything like that - nvm will only ever install the npm that comes with the given version of node.
This would be great. Literally every time I update node I have to google for the --reinstall-packages-from= bit.
So, despite my earlier comment, the next release of nvm will have nvm install-latest-npm and nvm install node --latest-npm, since the question "what is the latest npm version that works on a given node version, and how do i get it?" is surprisingly hard to answer.
Thus, nvm upgrade will be able to be largely achieved with nvm install node --reinstall-packages-from=node --latest-npm.
Most helpful comment
Gotcha, that's fair. My shell scripting knowledge isn't perfect, but I'll see if I can come up with a viable PR