nvm keeps "forgetting" node in new terminal session
Alias to node
itself to avoid updating the default alias along with node version updates later on.
nvm alias default node
To install the latest stable version:
nvm install stable
To set default to the stable version (instead of a specific version):
nvm alias default stable
To list installed versions:
nvm list
As of v6.2.0
, it will look something like:
$ nvm list
v4.4.2
-> v6.2.0
default -> stable (-> v6.2.0)
node -> stable (-> v6.2.0) (default)
stable -> 6.2 (-> v6.2.0) (default)
iojs -> N/A (default)
In my case, another program had added PATH
changes to .bashrc
If the other program changed the PATH
after nvm's initialisation, then nvm's PATH
changes would be forgotten, and we would get the system node on our PATH
(or no node).
The solution was to move the nvm setup to the bottom of .bashrc
### BAD .bashrc ###
# NVM initialisation
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Some other program adding to the PATH:
export PATH="$ANT_ROOT:$PATH"
Solution:
### GOOD .bashrc ###
# Some other program adding to the PATH:
export PATH="$ANT_ROOT:$PATH"
# NVM initialisation
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
(This was with bash 4.2.46 on CentOS. It seems to me like a bug in bash, but I may be mistaken.)
Try nvm alias default
. For example:
$ nvm alias default 0.12.7
This sets the default node version in your shell. Then verify that the change persists by closing the shell window, opening a new one, then:
node --version