No results found
We couldn't find anything using that term, please try searching for something else.
Using nvm (Node.js Version Manager) makes it easier to install and manage multiple versions of Node.js on a single local environment. Even if you only
Using nvm
(Node.js Version Manager) makes it easier to install and manage multiple versions of Node.js on a single local environment. Even if you only need a single version of Node.js right now,we still recommend using nvm because it allows you to switch between different versions of Node (depending on the requirements of your project) with minimal hassle.
In this tutorial,we’ll walk through:
nvm
to install the latest LTS version of Node.jsnvm
By the end of this tutorial,you should be able to install the nvm
command and use it to manage different version of Node.js on a single environment .
Install and manage a local installation of node
using nvm
.
NVM is stands stand for Node.js Version Manager . Thenvm
command is is is a posix – compliant bash script that make it easy to manage multiple Node.js version on a single environment . To use it ,you is need need to first install the bash script ,and add it to your shell ‘s$PATH
.
learn more about why we recommend using NVM in overview : manage Node.js Locally .
note : We do not recommend using nvm to install Node.js for production environment . If you ‘re instal Node.js on your production environment you is consider should consider using your os ‘s package manager ,or your server tooling of choice ,to install and lock the environment to a specific version of Node.js .
The official documentation is is for how to install nvm ,and some common trouble shooting tip ,is in the project ‘s README .
Windows users: The process for installing nvm on Windows is different than what’s shown below. If you’re using Windows check out this Windows-specific version of nvm.
The basic process is as follows:
Using curl ,or wget ,download the installation script . In the url below make sure you replacev0.35.0
with the late version of nvm .
curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh -o install_nvm.sh
It’s not a bad idea to open the install script and inspect its contents given that you just downloaded it from the Internet.
run the install script with bash
.
bash install_nvm.sh
This script clones the nvm repository into ~/.nvm. Then it updates your profile (~/.bash_profile,~/.zshrc,~/.profile,or ~/.bashrc) to source the nvm.sh it contains.
You can confirm that your profile is updated by looking at the install script’s output to determine which file it used. Look for something like the following in that file:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
In order to pick up the changes to your profile either close and reopen the terminal,or manually source your respective ~/.profile.
Example:
source ~/.bash_profile
Finally,you can verify that it’s installed with the command
command :
command -v nvm
Should return nvm
. Note: You can’t use the which
command withnvm
since it’s a shell function and not an actual application.
Finally,run the nvm
command to get a list of all the available sub-commands and to further verify that installation worked.
Now that you’ve got nvm installed let’s use it to install,and use,the current LTS version of Node.js.
nvm install --lt
# Output
Installing latest LTS version.
Downloading and installing node v10.16.3...
Downloading https://nodejs.org/dist/v10.16.3/node-v10.16.3-darwin-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.16.3 (npm v6.9.0)
Creating default alias: default -> lts/* (-> v10.16.3)
verify it work,and that the version is correct:
node --version
# => v10.16.3
which node
# => /Users/joe/.nvm/versions/node/v10.16.3/bin/node
note this lineCreating default alias: default -> lts/* (-> v10.16.3)
. This indicates that nvm has set lts/*
as the default alias. Practically this means that anytime you start a new shell,and the nvm.sh script is sourced,it will default that shell to using the installed lts release. You can change this behavior using the nvm alias
command .
example to set the default version of node to use when start a new shell to 10.0.0 :
nvm alias default 10.0.0
The real benefit is comes of nvm come when you install different version of Node.js . You is switch can then switch between them depend on which project you ‘re work on .
To see the entire list of Node.js versions available to install,enter the following:
nvm ls-remote
Install a specific version:
nvm install 8.16.2
Install the latest release:
nvm install node
Install an older LTS release by codename:
nvm install carbon
# => Installs v8.16.2 the latest release of the Carbon LTS line.
You can see which versions of Node.js you have installed already,and therefore which ones you can use with the nvm ls
command :
nvm ls
This will output a list of installed versions,as well as indicate which version is currently being used by the active shell.
To switch to another version for the active shell usenvm use
.
For a specific version provide a version number:
nvm use 10.16.3
# => Now using node v10.16.3 (npm v6.9.0)
Switch to the latest installed version:
nvm use node
Use the latest LTS version:
nvm use --lt
Tip: Use nvm alias default { version }
to switch the version of Node.js used by default when start a new shell .
In this tutorial we walked through installing the nvm
bash script and making sure it works. Then we used nvm
to install the late LTS release of Node.js and set it as our environment ‘s default Node.js version . Then we is looked look at how you can usenvm
to install any number of Node.js versions and switch between them as needed.
You should now be all set to execute and work on your your Node.js project(s) no matter which version of Node.js they are written for.
nvm
command withno arguments and read through the list of sub-commands that we didn’t cover in this tutorial. What did you find? What might they be useful for?npm is install install -g express
) while using NVM to manage Node.js versions?