Upgrade NodeJS to the latest version on Mac os

I am currently using NodeJS v0.6.16 on mac os x 10.7.4. Now I want to upgrade it to the latest NodeJS v0.8.1. But after downloading and installing the latest pkg file from nodejs.org, I find the system is still using v0.6.16 instead of v0.8.1 when I typed "node -v" in a terminal. Is there any step that I have missed? Or should I thoroughly uninstall the old version before installing the latest one?

BTW, I know that nvm can help to manage the nodejs package

https://github.com/creationix/nvm/

Is there any means to upgrade the nodejs without using it?

I have googled this problem, but it seems to me that there is no very clear answer to this question for the latest NodeJS. Many thanks.

Here's how I successfully upgraded from v0.8.18 to v0.10.20 without any other requirements like brew etc, (type these commands in terminal):

  1. sudo npm cache clean -f clear you npm cache
  2. sudo npm install -g n install "n" (this might take a while)
  3. sudo n stable upgrade to lastest version

Note that sudo might prompt your password.

If the version number doesn't show up when typing node -v, you might have to reboot.

How did you install it initially?

I use Homebrew for OS X and just did a brew update; brew upgrade node yesterday in Terminal, and everything worked as expected.

Then, npm update npm -g to update npm.

@Pascal notes that this has changed in the latest version of Homebrew.

in current brew version it states "If you update npm itself, do NOT use the npm update command. The upstream-recommended way to update npm is: npm install -g npm@latest"

Because this seems to be at the top of Google when searching for how to upgrade nodejs on mac I will offer my tip for anyone coming along in the future despite its age.

Upgrading via NPM
You can use the method described by @Mathias above or choose the following simpler method via the terminal.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

After which you may opt to confirm the upgrade

node -v

Your nodejs should have upgraded to the latest version. If you wish to upgrade to a specific one say v0.8.19 then instead of

sudo n stable

use

sudo n 0.8.19

Go to http://nodejs.org and download and run the installer. It works now - for me at least.

You could install nvm and have multiple versions of Node.js installed.

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

and then run:

nvm install 0.8.22  #(or whatever version of Node.js you want)

you can see what versions you have installed with :

nvm list

and you can change between versions with:

nvm use 0.8.22

The great thing about using NVM is that you can test different versions alongside one another. If different apps require different versions of Node.js, you can run them both.

On Mac OS X 10.10 Yosemite the homebrew recommended way is to run

npm install -g npm@latest

enter image description here

You can run but you can't hide... At the end you will be using NVM anyways.