Node.js lets you run JavaScript outside the browser. Installing it and managing versions helps you work on different projects smoothly.
0
0
Node.js installation and version management in Node.js
Introduction
When starting to build a JavaScript app that runs on your computer or server.
When you need to switch between different Node.js versions for different projects.
When updating Node.js to get new features or security fixes.
When setting up a new computer for coding with Node.js.
When troubleshooting issues caused by incompatible Node.js versions.
Syntax
Node.js
nvm install <version> nvm use <version> nvm ls node -v npm -v
nvm stands for Node Version Manager, a tool to install and switch Node.js versions easily.
Use node -v to check the current Node.js version and npm -v for the package manager version.
Examples
Installs Node.js version 20.0.0 on your computer.
Node.js
nvm install 20.0.0Switches your current terminal session to use Node.js version 20.0.0.
Node.js
nvm use 20.0.0Lists all Node.js versions installed on your machine and shows which one is active.
Node.js
nvm ls
Shows the version of Node.js currently in use.
Node.js
node -v
Sample Program
This example shows how to install a specific Node.js version, switch to it, and verify the versions of Node.js and npm.
Node.js
# Step 1: Install Node.js version 20.0.0 nvm install 20.0.0 # Step 2: Use Node.js version 20.0.0 nvm use 20.0.0 # Step 3: Check Node.js version node -v # Step 4: Check npm version npm -v
OutputSuccess
Important Notes
Always use nvm to switch Node.js versions instead of reinstalling manually.
After switching versions, restart your terminal to avoid conflicts.
Keep your Node.js and npm updated for best performance and security.
Summary
Node.js installation lets you run JavaScript on your computer.
Use nvm to install and switch between Node.js versions easily.
Check your current Node.js and npm versions with node -v and npm -v.