Installing Node With NVM

In this tutorial, you will learn about NVM and how you can use it to install Node.js.  NVM stands for Node version manager.  You can use NVM to install Node. If you are starting off with Node then simply install it on your computer will do.  When you work in a large company and you have multiple projects to work on, things become trickier.

Like all good programming languages, node release updates every once in a while.  With each new update of node comes new features, syntax improvements etc..  if you write a script in Node 10 using some new feature, then it might not run in Node 8.  At work, if you have two apps, one that only works on Node 10, one that works on Node 8, what do you do?  Constantly, uninstalling and re-installing Node is a pain...this is where NVM comes into play.  NVM is an essential tool to know about because of out-of-the-box Node will just install itself.

How To Install NVM

You can install NVM via homebrew.  You can download homebrew using instructions from here, using this command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After installing homebrew, close and open your terminal, then type:

brew update
brew install nvm

Next, type in:

mkdir ~/.nvm

Next, you will likely need to create and configure a bash profile and create an alias for NVM.  You can do this within the terminal, by typing:

nano ~/.bash_profile

In here, if you do not see anything related to NVM then add in this snippet:

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

Save the file (CTRL + O) then (CTRL + X). Close and re-open the terminal. type,now type:

nvm --version

If everything has gone according to plan it should load OK.

How To Install NPM with NVM

Now you have NVM installed, we can install Node. To install Node you can type:

nvm install node

Use the latest version with:

nvm use node

To install the latest version:

nvm install --lts
nvm use --lts

 

submit to reddit

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top