9

Node installed.js ver 0.8 but node --version still shows the previous version 0....

 3 years ago
source link: https://www.codesd.com/item/node-installed-js-ver-0-8-but-node-version-still-shows-the-previous-version-0-6-12.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Node installed.js ver 0.8 but node --version still shows the previous version 0.6.12

advertisements

I tried installing node ver 0.8 on my ubuntu 12.04.It already has a node ver 0.6.12.The installation went suceesfully but when i type in

node --version

it still shows previous version. i tried to remove previous version using sudo apt-get remove node but it says package node is not installed.But on trying node --version it shows 0.6.12 Why is it so??


The problem is, you need to replace the new location for node with the old in your PATH variable. If you have an old manual install, find the old path to node by running echo $PATH. Then run this command:

export PATH=${PATH%$OLD_NODE_PATH/bin*}$NEW_NODE_PATH/bin${PATH#$*OLD_NODE_PATH/bin}

Or if you are using an install from the apt-get repository, just run:

export PATH=$NEW_NODE_PATH/bin

And that should fix your problem. But there is a better way! The best tool to manage your node.js environment is NVM. It exactly like RVM for ruby and similar to virtualenv for python, if you are familiar with those tools. It allows you to switch versions of node and download new ones extremely efficiently, and is easy to use. Download and install with:

curl https://raw.github.com/creationix/nvm/master/install.sh | sh

Then add this line to your bash (assuming you are running a bash shell) where it will be loaded (I prefer .bash_login for the personal stuff although it is not loaded by default):

[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh

Source your bash script or restart the terminal then enter this command:

nvm install 0.8.0 && nvm use 0.8.0

This should set you up just fine. Although not necessary, you should probably get rid of all the other node installs, for the sake of tidiness. Check out their github page but to get you started here is a quick overview:

nvm ls                   # list all installed versions of node
nvm ls-remote            # list all available versions of node
nvm install 0.9.8        # download and install node v0.9.8
nvm use 0.8.0            # switch current environment to use node v0.8.0
nvm alias default 0.8.0  # set 0.8.0 as default, you can use 'nvm use default'
nvm deactivate           # use system install of node
nvm run default app.js   # run app.js with default node version


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK