node.jsnpm

how to set specific version of node as default using n


I've installed node using the npm by below commands.

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

sudo n 8 installed node 8 .

$ sudo n 8
 install : node-v8.11.3
   mkdir : /usr/local/n/versions/node/8.11.3
   fetch : https://nodejs.org/dist/v8.11.3/node-v8.11.3-darwin-x64.tar.gz
   ######################################################################## 100.0%
  installed : v6.13.1

but didn't set it as default

 $ node -v
 v6.13.1

How can I set node version 8 as default node version.


Solution

  • You still need to activate the installed version, installing doesn't automatically switch to that version. Type n after doing the install and select the version you want. From that point forward, it will be the node version your system uses. You may need to use sudo n if you run into permission issues.