Basics
Node.js Installation
Installing Node.js
Node.js installation uses npm and nvm to manage versions for development.
Introduction to Node.js Installation
Node.js is a powerful JavaScript runtime that allows you to run JavaScript on the server-side. To work efficiently with Node.js, managing different versions is crucial, especially when working on multiple projects. This guide will walk you through the installation of Node.js using two tools: npm (Node Package Manager) and nvm (Node Version Manager).
Installing Node.js with npm
npm is the default package manager for Node.js and can be used to install Node.js itself. Follow these steps to install Node.js using npm:
- Download the Node.js installer from the official Node.js website.
- Run the installer and follow the on-screen instructions.
- To verify the installation, open your terminal and run the following command:
This command will display the installed version of Node.js, confirming the installation.
Using nvm to Manage Node.js Versions
nvm is a popular tool that allows you to install and switch between different versions of Node.js effortlessly. It is especially useful if you need to test your application against different Node.js versions. Here’s how you can install and use nvm:
Installing nvm
To install nvm, you need to use the command line. Run the following command to download and install nvm:
Once installed, you may need to restart your terminal or run the following command to load nvm:
Verify the installation by checking the nvm version:
Installing Node.js with nvm
With nvm installed, you can now install Node.js. Use the following commands to install and activate a specific version of Node.js:
This command installs the latest available Node.js version. To install a specific version, replace node
with the desired version number, like nvm install 14.17.0
.
To switch between installed versions, use:
Where 14.17.0
is the version you wish to use. Verify the active version with:
This will confirm that the version switch was successful.
Basics
- Previous
- Introduction
- Next
- Running Code