How to run multiple versions of Node.js on Linux
source link: https://computingforgeeks.com/how-to-run-multiple-versions-of-node-js-on-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
In this guide, I’ll show you how you can run multiple versions of Node.js on Linux using Node Version Manager (NVM). NVM is a simple bash script to manage multiple active node.js versions using your favorite Linux terminal.
How to Install Node Version Manager on Linux
Node Version Manager project provides a script which automates the installation for you. Install it by simply running the commands below:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
The script will clone the nvm repository to ~/.nvm
directory and adds the following source line to your profile: (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
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
If you’re a zsh
user, add the lines to your ~/.zshrc
file.
To verify that nvm has been installed, do:
$ source ~/.bashrc
$ command -v nvm
nvm
This should output ‘nvm‘ if the installation was successful.
How to use nvm to manage Node.js versions
Now that you have installed nvm, let’s look at how you can use it to manage the versions of Node.js installed on your system.
Check available versions of Node.js
Check versions that can be installed:
$ nvm ls-remote
.................................
v10.13.0 (LTS: Dubnium)
v10.14.0 (LTS: Dubnium)
v10.14.1 (LTS: Dubnium)
v10.14.2 (LTS: Dubnium)
v10.15.0 (LTS: Dubnium)
v10.15.1 (LTS: Dubnium)
v10.15.2 (LTS: Dubnium)
v10.15.3 (Latest LTS: Dubnium)
v11.0.0
v11.1.0
v11.2.0
v11.3.0
v11.4.0
v11.5.0
v11.6.0
v11.7.0
v11.8.0
v11.9.0
v11.10.0
v11.10.1
v11.11.0
v11.12.0
v11.13.0
v11.14.0
-> v12.0.0
Install Latest version of Node.js
To download, compile, and install the latest release of node, run:
$ nvm install node
Downloading and installing node v12.0.0...
Downloading https://nodejs.org/dist/v12.0.0/node-v12.0.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.0.0 (npm v6.9.0)
Creating default alias: default -> node (-> v12.0.0)
Install Specific version of Node.js
Install a specific version of node, provide version number as an argument to nvm install command.
$ nvm install v11.14.0
Downloading and installing node v11.14.0...
Downloading https://nodejs.org/dist/v11.14.0/node-v11.14.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v11.14.0 (npm v6.7.0)
Install Node.js LTS version
This installs the latest LTS release of node.
$ nvm install --lts
Installing latest LTS version.
Downloading and installing node v10.15.3...
Downloading https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.15.3 (npm v6.4.1)
List installed Node.js versions
To check installed versions, use:
$ nvm ls
-> v11.14.0
v12.0.0
default -> node (-> v12.0.0)
node -> stable (-> v12.0.0) (default)
stable -> 12.0 (-> v12.0.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/dubnium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.16.0 (-> N/A)
lts/dubnium -> v10.15.3 (-> N/A)
Use Latest Node.js
To use the latest version on the shell, run:
$ nvm use node
Now using node v12.0.0 (npm v6.9.0)
Use a specific version of node:
Specify version number.
$ nvm use v11.14.0
Now using node v11.14.0 (npm v6.7.0)
Migrating global packages while installing:
If you want to install a new version of Node.js and migrate npm packages from a previous version:
$ nvm install node --reinstall-packages-from=node
To use the system version of node, add system at the end of use.
$ nvm use system
$ nvm run system --version
To restore your PATH, you can deactivate it:
nvm deactivate
For more usage examples, visit nvm Github page.
Similar articles:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK