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

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/

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

Seem like you install nodejs package from Ubuntu repo and manually install node 0.8 after? Try remove nodejs package.

The way to get a more recent version of Node.js is to add a PPA (personal package archive) maintained by NodeSource. This will probably have more up-to-date versions of Node.js than the official Ubuntu repositories.

First, you need to install the PPA in order to get access to its contents:

curl -sL https://deb.nodesource.com/setup | sudo bash -

The PPA will be added to your configuration and your local package cache will be updated automatically. After running the setup script from nodesource, you can install the Node.js package using the below command.

sudo apt-get install nodejs

You can check the node by using this command

node -v