You can install XCode from the AppStore. Once done, install the XCode Command Line tools.
xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then check to make sure everything is installed correctly. brew doctor
brew install node --without-npm
echo prefix=~/.node >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
Edit your ~/.profile or ~/.bash_profile file and add the following line:
export PATH="$HOME/.node/bin:$PATH" # Add NPM to PATH for scripting
Then, reload your environment profile:
source ~/.bash_profile
npm install -g n
For more information on 'n', please see https://github.com/tj/n