Node Version Manager (NVM) as the name says using NVM multiple node.js can be installed, managed, and used on single. Using NVM On Linux, a specific version of the node can be installed or multiple node.js can be installed. You can visit the NVM Github Readme page for more information.
The node can be installed directly using apt install node
but it doesn’t install the latest version and to get the latest version, managing multiple versions of the node is difficult for a rookie like me. So its good to use NVM saves time and is easy to use On Linux.
Covered Topics
3 Easy Steps To Install Node.js
- Install NVM.
- Install Node.js using NVM.
- Run Node.js
In short Installation of Nodejs on Linux:
- Install NVM by
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
- Now install Nodejs by NVM using
nvm install v12.18.0
- Success! Now Bookmark our blog 😛
Installing Node.js On Linux – Detailed Guide
#1. Install NVM on Linux
- Run NVM script to install NVM using below cURL
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash
- If you dont have cURL installed then use this command then run the NVM script
sudo apt-get install curl
- Now exit your terminal and reopen it.
- Check NVM is installed and working using
nvm --version
Output:Geekyarea@chetan:~$ nvm --version 0.35.3 Geekyarea@chetan:~$
#2. Install Node.js using NVM
- Open nodejs.org and note down the version OR run
nvm ls-remote
to get all node versions.Output: (The Green colored version are stable and recommended by nodejs)v12.16.3 (LTS: Erbium) v12.17.0 (LTS: Erbium) -> v12.18.0 (Latest LTS: Erbium) v13.0.0...
- Run
nvm install v12.18.0
to install Node.js. You can install any version, here I am installing v12.18.0 as its suitable and most stable.Output:Downloading and installing node v12.18.0... Downloading https://nodejs.org/dist/v12.18.0/node-v12.18.0-linux-x64.tar.xz... ######################################################################## 100.0% Computing checksum with sha256sum Checksums matched! Now using node v12.18.0 (npm v6.14.4) Creating default alias: default -> v12.18.0
#3. Run Nodejs
Check node is installed and working by executing node --version
Output:
Geekyarea@Chetan:~$ node --version v12.18.0 Geekyarea@Chetan:~$
PS: If this is the first time installing and learning node then you should stop here. If your trying other versions of the node then go ahead to managing multiple node.js using NVM.
Installing and Managing Multiple Node using NVM
I use the latest version of node and here you want to install or try a different version of node, I wanted to know why? Its none of my business but still its feels good to know and learn from you.
Once after installing NVM it becomes too easy to install and manage multiple Nodejs of different versions. All thanks to NVM.
#1. Installing Specific version of Node
As usual, just run the following command with the version of node you want without [](square bracket)
nvm install v[version here]
Example: nvm install v12.18.0
#2. Setting a Default Node
nvm alias default [version here]
specifying a version will set that node as default.
If you want set stable version of the node then nvm alias default stable
This will set the most stable available version of the node as default.
#3. Switch from one version Node to another version of Node
Even this is made so easy by NVM, just run the following command with our same old friend know as the version you wanted to use.
nvm use v[version here]
#4. Listing all the Installed Nodejs
nvm ls
display all the installed versions of Nodejs on the system/server. Not only list but tells us the default, stable(installed), stable available too.
Geekyarea@chetan:~$ nvm ls -> v12.18.0 system default -> v12.18.0 node -> stable (-> v12.18.0) (default) stable -> 12.18 (-> v12.18.0) (default) iojs -> N/A (default) unstable -> N/A (default) lts/* -> lts/erbium (-> v12.18.0) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.17.0 (-> N/A) lts/dubnium -> v10.21.0 (-> N/A) lts/erbium -> v12.18.0
#5. Run using a specific version of node
Running a specific version of the node can be done by nvm run [version_here] app.js
#6. Uninstalling/Removing Node.js
When I was trying node for the first time, I thought removing other versions of the node would be difficult as compared to installing and surprise. And the command to uninstall/remove node is
nvm uninstall [version_here]
Final Words On Installing and Managing Node.js using NVM on Linux
Oh well, I will more happy if you share your project link, or show me what you have built with Node.js and me as a beginner to Node I will be happy to learn something from you.
Beside few words are, the distro I used to install and write this guide is Ubuntu 20.04 and 18.04. You should not get any errors as far your using the same distro or on any Ubuntu-based distros like Pop OS.
And if you tried out this guide and worked (even with some workaround) on other distros, comment down for your fellow NodeMates XD. Bye Bye!