l2t

How to install NVM?

how to install nvm on MacOs or Linux?

What is NVM (Node Version Manager)?

NVM is a command line tool that allows you to manage different versions of NodeJS. It is known as Node Version Manager and you can easily install this tool on linux or mac or windows machine.

If you are working on different node projects where you have to switch between different node versions nvm will be your best option.

How to Install NVM on Linux or Ubuntu?

To install NVM on your linux or Ubuntu machine you should have curl installed. If you do not know how to install curl try following command:

sudo apt-get install curl​

Once curl is installed you can run following commands to install nvm on linux machine:

# Install nvm using curl
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

# or if you do not have curl try
# installing using wget command
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

# check if nvm is installed
nvm -v

# now that nvm is installedd 
# let's install latest node
nvm install node

# if you want to install different versions
# syntax: nvm install <version>
nvm install v9.2.0
nvm install v8.9.1

# switch to another 
# node version
# syntax: nvm use <version>
nvm use 9.2.0

# make node version to default
# syntax: nvm alias default <version>
nvm alias default v8.9.1

# to uninstall node version
# syntax: nvm uninstall <version>
nvm uninstall v8.9.0

How To Install NVM on macOS using brew?

In order to install nvm on your mac machine using home brew follow the steps below:

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

# If you already have homebrew and want to upgrade
cd "$(brew --repo)" git fetch && git reset --hard origin/master && brew update

# check to see if installation is successful
brew --version

# uninstall old node version
brew uninstall --ignore-dependencies node 
brew uninstall --force node 

# install nvm using brew
brew update 
brew install nvm

# create nvm directory
mkdir ~/.nvm 

# open bash profile in nano or vim editor
nano ~/.bash_profile OR vim ~/.bash_profile 

# add following line of code
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

# apply new changes
source ~/.bash_profile

# check if nvm is installed
nvm -v

# now that nvm is installedd 
# let's install latest node
nvm install node

# if you want to install different versions
# syntax: nvm install <version>
nvm install v9.2.0
nvm install v8.9.1

# switch to another 
# node version
# syntax: nvm use <version>
nvm use 9.2.0

# make node version to default
# syntax: nvm alias default <version>
nvm alias default v8.9.1

# to uninstall node version
# syntax: nvm uninstall <version>
nvm uninstall v8.9.0

How To Install NVM on macOS using curl or wget?

If you have curl or wget installed already on your mac os and want to install nvm using wget or curl try following commands:

# Install nvm using curl
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

# or if you do not have curl try
# installing using wget command
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

# check if nvm is installed
nvm -v

# let's install different versions of node
nvm install v8.9.1
nvm install v9.2.0

# check the default 
# version of node
node -v

# switch to another 
# node version
nvm use 9.2.0

# make node version to default
nvm alias default v8.9.1

# to uninstall nvm
nvm uninstall v8.9.0​

Above commands can be used for any linux based operating system like ubuntu as well.