Node.js reverts to 0.4 form 0.6 on reboot (NVM)

I used nvm (node ​​version manager) to upgrade node form v0.4 to v0.6.9. I used the following commands:

node -v -> v0.4.x cd ~ git clone git://github.com/creationix/nvm.git ~/.nvm . ~/.nvm/nvm.sh nvm install v0.6.9 //wait a while node -v -> v0.6.9 

The problem is that every time I restart my mac, node -v prints v0.4. Therefore, I must repeat the procedure. I also need to run rm -rf .nvm before git clone . Could you tell me why this is happening and how I can fix it? Thanks.

+4
source share
4 answers

The information that I think you are missing is that nvm allows you to manage multiple versions at once. He does this by playing magic with your surroundings and paths.

After rebooting, I suspect that you only need to run the following lines:

 . ~/.nvm/nvm.sh nvm use v0.6.9 

This should result in re-entering the "magic" nvm environment that you previously installed v0.6.9 inches.

+4
source

It is good that nvm installs node in a directory that is not in the usual executable path (/ usr / bin /), so its path must be placed in the PATH environment variable each time the console or terminal is opened, which does . ~/.nvm/nvm.sh . ~/.nvm/nvm.sh Therefore, you must do this every time you open a console or terminal. Technically, you can also use node with the path as follows:

 /home/alfred/.nvm/v0.6.7/bin/node -v 

And if you want to automatically set your node path, you should just put this line in . ~/.nvm/nvm.sh . ~/.nvm/nvm.sh to your ~/.bashrc or ~/.profile files. And after each launch of the terminal you will have a node.

+1
source

Run this command to see what is currently running:

 node -v ; which node ; echo $PATH ; npm root -g 

Now install the new version of node you want:

 nvm install xxx 

Now install this new version as the default version:

 nvm alias default xxx 

This will not change anything in your current session, so create a new session and then try again:

 node -v ; which node ; echo $PATH ; npm root -g 

Now you need to show that the new version that you installed is now in use.

0
source

The easiest way I've found is this:

 nvm alias default v8.4.0 

(enter your version number, of course)

0
source

Source: https://habr.com/ru/post/1395148/


All Articles