May 24, 2024 · 862 words · 4 min read
We all know that, Node.js is the runtime environment for JavaScript that executes JavaScript code outside the web browser. And, npm stands for Node Package Manager and is the default package manager for Node.js and is also a platform for managing JavaScript packages. It provides a command-line interface (CLI) for interacting with the npm registry, which hosts thousands of open-source libraries and modules.
Based on the operating systems, the installation process is different and varied. That's why, I'm classifying them here so that you folks don't get confused between them.
Download the Installer:
Run the Installer:
.msi file and run the installer.You have to install Homebrew if you haven't already. To do that, open the terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Now, we can install node.js and npm with Homebrew:
brew install node
It's extremely easy to install node.js and npm in Linux. Just run these two commands in the terminal:
sudo apt update
sudo apt install nodejs npm
You can verify the installation of node.js and npm by running the following two commands in your terminal:
node -v
npm -v
If you are on Windows, Powershell may cause some issues, so try to use Command Prompt in that case. It will work!!
NVM stands for Node Version Manager and it's a command-line tool that helps us to manage and switch different versions of Node.js with ease and convenience!!
Before installing any node version, let's first check the available Node versions. To do that, we can simply run the following command in our terminal:
nvm ls available
After running this, you get something like this:
To install the latest version of node.js, you can simply run this command,
nvm install latest
But remember, it's always better to install the LTS (long-term support) version of node, because it's less buggy and is overall more stable!!
To install the LTS version of Node, run the command,-
nvm install lts
One of the most interesting part of NVM is you can install multiple versions of Node at the same time and use any of them based on your convenience!!
For this, nvm has the nvm install command. You can install specific versions by running this command followed by the version you want. For example,
nvm install 18.17.0
nvm install 20.11.1
nvm install 20.12
Also, as NVM follows semantic versioning, you can install v18.17 and use any of the following version under 18.17, like 18.17.0, 18.17.1, etc. Here, 18 represents the major version, 17 represents the minor version, and 1 represents the patch version!!
You can install any specific node version, by running this command,-
nvm install <node_version_number>
Replace the <node_version_number> with your desired Node version.
But, to ensure that your given version is valid, make sure to run nvm ls available and put a correct version from the list!!
Also, once you install a version of Node, the corresponding version of NPM is also installed alongside with it. So you don’t need to install NPM separately!!
To check the list of all node versions that you have installed on your system, you can simply run,-
nvm list
And, you will see a response like this:
As you can see in the previous image that I'm currently using 20.13.1. Now, if I want to switch my version to another one like 18.17.0. I can simply use the following command:
nvm use 18.17.0
In your case, you can put your desired version in place of 18.17.0, but first make sure it is a valid version number and it is installed on your system!!
To uninstall an already installed Node version that you no longer think is useful, you can do that by running the command,-
nvm uninstall <node_version_number>
Replace the <node_version_number> with your desired and installed Node version.
TLDR: This article provides a comprehensive guide on installing Node.js and npm across different operating systems (Windows, macOS, and Linux), verifying installations, and managing Node.js versions using NVM (Node Version Manager). It covers steps to install specific Node.js versions, switch between versions, and uninstall versions when no longer needed. The guide emphasizes the importance of using the LTS (Long Term Support) version for stability and includes detailed commands for each process.
Well, that's a wrap for now!! Hope you folks have enriched yourself today with lots of known or unknown concepts. I wish you a great day ahead and till then keep learning and keep exploring!!