Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installed node.js ver 0.8 but node --version still shows previous version 0.6.12

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??

like image 391
iJade Avatar asked Feb 01 '13 04:02

iJade


2 Answers

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
like image 183
dward Avatar answered Sep 28 '22 07:09

dward


I had this issue until I followd the directions on https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

which included running:

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update

first. Then running sudo apt-get install nodejs npm got me to 0.8.x

Also see: http://apptob.org/

like image 45
philfreo Avatar answered Sep 28 '22 05:09

philfreo