How to update nvm
If nvm has a command that will update himself, it will be more awesome. Now the method i know is remove nvm and reinstall, but this will set all my node reinstall
I always install by cloning from git. Then if I want to update, I simply do a git pull.
That said, why would you upgrade if it's working? Personally I've never upgraded nvm after installing it on a machine. (though my operating system install lifetimes are fairly short). If you learn about a new feature that you need, then git pull and you're done.
Remember that every feature added has a cost. Could you explain what exactly makes it more awesome? Perhaps I'm not understanding your use case.
Duplicate of #127
Also, you don't have to ever remove nvm - just install the newer version, and it will replace the older one.
I feel #127 shouldn't be closed now that users are not supposed to run from master but from a tagged commit. I use the following script:
#!/bin/sh
set -e
cd ~/.nvm
git fetch --tags
TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "Checking out tag $TAG..."
git checkout "$TAG"
source ~/.nvm/nvm.sh
+1
+1
It appears that simply effectively re-installing over an existing nvm actually updates it. This would be a really trivial script.
I believe this should do it. The $@ is optional, but mostly for debugging (Depends on either curl or wget, preferring the former.)
#!/bin/sh
download() {
if which curl > /dev/null; then
curl -s $@
else
wget -qO- $@
fi
}
download https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | /usr/bin/env bash $@
Or, if you'd prefer a giant one-liner, here it is. This one should also work with csh, although I don't have one installed to test with. It's probably the most portable. It is alias-safe if you drop the last $@, but make sure to use double-quotes.
#!/bin/sh
`which curl > /dev/null && printf 'curl -s' || printf 'wget -qO-'` https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | /usr/bin/env bash $@
Both have been tested in dash and bash, and they should be fairly portable, even with older shells.
If you want to add support for using Git, it'll take bit more logic and a lot of Git "plumbing" commands, such as git ls-remote -t https://github.com/creationix/nvm.git (lists commits and tags, but former needs filtered out). Long story short, it's far from trivial.
Maybe that could be put into nvm.sh somewhere.
It's trivial for a user, because you already know your preferred installation method.
However, nvm can be installed via curl, wget, git clone, or even simple file copying. It is in no way trivial to include in the actual product.
The only current blessed way to install and update nvm, is the ones I've mentioned - and I strongly encourage the curl command in the README on the git tag for the latest release.
You could probably do something similar, just retrieving the current version first, and then the install script similarly. Mine tries the curl method first (fixed to be silent like wget).
@mzgol
Thanks for your script! I have two questions about it:
- Can I run this script in a shell that has run
source ~/.nvm/nvm.shbefore? I mean, is there any side-effect innvm.sh(that may cause problems ifnvm.shis run more than once)? - Do I have to install Node.js again after updating nvm? IIRC Node.js is installed exactly in the
~/.nvmdirectory.
@xfq nvm unload will completely unload nvm from the shell, so even if it wasn't safe to re-source (it is), you could unload it first if you wanted.
@ljharb I see. Thank you. What about the second question?
You shouldn't need to reinstall any node versions after updating nvm, no.
I have just tried reinstalling NVM - Lees-MacBook-Pro-2:~ leeblazek$ curl https://raw.githubusercontent.com/creationix/nvm/v0.23.0/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 5205 100 5205 0 0 17370 0 --:--:-- --:--:-- --:--:-- 17408 => nvm is already installed in /Users/leeblazek/.nvm, trying to update => Lees-MacBook-Pro-2:~ leeblazek$
But it just doesn't seem to do anything? I have also tried sudo, but still the same non-result
Any ideas?
@surfjedi This was reported in https://github.com/creationix/nvm/issues/559#issuecomment-70946574 - can you try METHOD=git . install.sh and see what happens?
@ljharb I faced same problem as @surfjedi, and running METHOD=git . install.sh helped, thanks.
What does this even mean?!?!?!! gahhh
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.23.3/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5226 100 5226 0 0 18866 0 --:--:-- --:--:-- --:--:-- 18934
=> nvm is already installed in /Users/thomas/.nvm, trying to update using git
=>
=> Appending source string to /Users/thomas/.bashrc
=> Close and reopen your terminal to start using nvm
@reggi it means it's installed? Is something confusing about that?
Sorry I was super confused on how to update nvm.
I didn't find any information on this:
/Users/thomas/.nvm, trying to update using git
I did this and it worked:
cd /Users/thomas/.nvm
git pull origin master
@reggi That message was correct, what was the problem?
On the other hand, via your last command you updated to master, i.e. an unstable version that may just not work.
Hey @mzgol and @ljharb
Sorry about my first message in this issue. It wasn't helpful to the community or beneficial to this issue.
I had done some searching for how to update nvm, very confusingly updated with npm by accident npm install nvm -g. Then I remembered that nvm isn't on npm, yet at least. So I had to npm uninstall nvm -g.
Then I ran nvm unload without any clue what that would do (not the best of ideas). It messed up nvm and I had no clue how to reload it.
Then I ran git pull origin master and because I had run nvm unload the nvm command wasn't working. I don't also know where the actual nvm binary is stored, which is also confusing.
I ended up moving /Users/thomas/.nvm to /Users/thomas/.oldnvm and reinstalling, and I'm unsure if there's anything in there that I needed like global modules, or where those live or if those live on a node-level basis.
There's surprisingly no documentation on how to update nvm itself and was pretty frustrating. I still don't know the proper way and would love to see something in the README.md about it.
For something so simple as updating I shouldn't have gone through such a hassle.
fwiw, nvm unload just uninstalls it from the current shell - open a new shell, nvm will be fine.
The nvm that's on npm will be replaced once nvm hits v1.0 - which will include providing an nvm update.
The reality, though, is that the curl command in the README will always install the proper version of nvm, and like all software, will replace any existing installations. In other words, the way to update any software is always, by default, "install the new version in place".
How about something like:
git fetch -p
git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
source ~/.nvm/nvm.sh
This will ensure that the repo is updated, checkout the latest tag and re-source the shell script.
Per the nvm documentation (https://github.com/creationix/nvm#manual-install), it seems indicate using the following command:
git checkout `git describe --abbrev=0 --tags`
but as shown below, this does not actually point to the correct version after updating the repo.
[user@server .nvm]$ nvm --version
v0.23.3
[user@server .nvm]$ git fetch -p
remote: Counting objects: 145, done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 145 (delta 43), reused 28 (delta 27), pack-reused 75
Receiving objects: 100% (145/145), 41.70 KiB, done.
Resolving deltas: 100% (73/73), done.
From https://github.com/creationix/nvm
f0d81e2..70370a8 master -> origin/master
From https://github.com/creationix/nvm
* [new tag] v0.24.0 -> v0.24.0
[user@server .nvm]$ git rev-list --tags --max-count=1
5802ac3ea751bdd66cba75302b3b322109be90f8
[user@server .nvm]$ git describe --tags 5802ac3ea751bdd66cba75302b3b322109be90f8
v0.24.0
[user@server .nvm]$ git describe --abbrev=0 --tags
v0.23.3
[user@server .nvm]$ git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
Previous HEAD position was 0f1f3ed... v0.23.3
HEAD is now at 5802ac3... v0.24.0
[user@server .nvm]$ source ~/.nvm/nvm.sh
[user@server .nvm]$ nvm --version
0.24.0
Then maybe all that would be necessary is including a nvm update command to run these commands to update nvm. But likely using the NVM_DIR variable in the event that nvm isn't installed in the default ~/.nvm location.
@animedbz16 What version of git are you using? On my machine git describe --abbrev=0 --tags definitely returns v0.24.0, but I do have the config setting tag.sort set to version:refname, which may affect this.
Also, please remember that nvm can currently be installed without having git installed, so that's not necessarily a reliable update mechanism, although it may end up being the simplest.
@ljharb
Currently using git version 1.7.1 on RHEL server. The only things in my git config are user.name, user.email, color.ui=auto, and push.default=current
I would think that most users/systems that are using nvm would have git installed on their system and thus could use this method to perform a nvm update.
For those systems that don't have access to git, a nvm update command could just indicate to the user that it could not detect git and provide some links/information to github repo on how to update via curl/wget via the script.
Maybe at a later point a more sophisticated update script could also automate the curl/wget nvm updating, by curling the github repository for the latest version and then downloading the correct installation/update script/procedures.
That version of git is old and has security issues - you should upgrade to 2.2 or 2.3 immediately. The install script doesn't work with that old a version of git either. nvm already has an internal nvm_get_latest function that uses curl to determine the latest version of nvm.
I do like the idea that nvm update would require git, but that the normal installation procedure could work without it - however, there'd need to be an easy way to upgrade $NVM_DIR to a git repo without affecting the node/io.js installations underneath it.
To install, I git clone to ~/.nvm.
To upgrade, I run sh ~/.nvm/install.sh
Is this a good way to do this?
@jokeyrhyme Perfect, except for one step - after the clone/fetch, before running the install script, you'll want to check out the latest tagged release - either git checkout v0.26.1 manually, or, the command referenced in https://github.com/creationix/nvm/issues/400#issuecomment-85047457
@ljharb ah, so it's possible that the master version of install.sh could be broken, so use a tagged install.sh to update to the latest tagged nvm?