Node.js installation process
Installing Node.js involves setting up the runtime environment on your system so you can start building and running Node.js applications. Here’s a step-by-step guide to installing Node.js on various operating systems:
1. Installation on Windows
Using the Node.js Installer
Download the Installer:
- Go to the Node.js official website.
- Click on the “Downloads” tab.
- Choose the Windows installer (.msi) for the LTS (Long-Term Support) or Current version, depending on your needs.
Run the Installer:
- Double-click the downloaded
.msi
file. - Follow the prompts in the Node.js Setup Wizard. You can accept the default options.
- Make sure to check the box that says "Automatically install the necessary tools" if you need build tools like Python.
- Double-click the downloaded
Verify Installation:
- Open the Command Prompt (cmd) or PowerShell.
- Run the following commands to verify Node.js and npm (Node Package Manager) are installed correctly:
node -v npm -v
- These commands will display the version numbers if the installation was successful.
2. Installation on macOS
Using the Node.js Installer
Download the Installer:
- Visit the Node.js official website.
- Click on the “Downloads” tab.
- Download the macOS installer (.pkg) for the LTS or Current version.
Run the Installer:
- Double-click the downloaded
.pkg
file. - Follow the instructions in the installation wizard.
- Double-click the downloaded
Verify Installation:
- Open the Terminal.
- Run the following commands to check the Node.js and npm versions:
node -v npm -v
Using Homebrew (Alternative Method)
Install Homebrew (if not already installed):
- Open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Open Terminal and run:
Install Node.js:
- Run:
brew install node
- Run:
Verify Installation:
- Check the Node.js and npm versions:
node -v npm -v
- Check the Node.js and npm versions:
3. Installation on Linux
Using a Package Manager
For Ubuntu/Debian-based Distributions:
Update the Package Index:
- Open Terminal and run:
sudo apt update
- Open Terminal and run:
Install Node.js:
- You can install Node.js from the official repository:
sudo apt install nodejs sudo apt install npm
- You can install Node.js from the official repository:
Verify Installation:
- Check the installed versions:
node -v npm -v
- Check the installed versions:
For Fedora/RHEL-based Distributions:
Install Node.js:
- Open Terminal and run:
sudo dnf install nodejs
- Open Terminal and run:
Verify Installation:
- Check the Node.js and npm versions:
node -v npm -v
- Check the Node.js and npm versions:
Using Node Version Manager (nvm)
nvm
allows you to manage multiple Node.js versions on your machine.
Install nvm:
- Open Terminal and run:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- Open Terminal and run:
Load nvm:
- Run:
source ~/.bashrc
- or for zsh:
source ~/.zshrc
- Run:
Install Node.js Using nvm:
- List available versions:
nvm ls-remote
- Install a specific version (e.g.,
16.20.0
):nvm install 16.20.0
- Set a default version:
nvm alias default 16.20.0
- List available versions:
Verify Installation:
- Check the Node.js and npm versions:
node -v npm -v
- Check the Node.js and npm versions:
4. Post-Installation
After installing Node.js, you might want to:
- Install Global Packages: Use npm to install global packages:
npm install -g <package-name>
- Set Up a Project: Create a new Node.js project with:
mkdir my-project cd my-project npm init
Summary
- Windows: Use the .msi installer from the Node.js website.
- macOS: Use the .pkg installer or Homebrew.
- Linux: Use the package manager or nvm for multiple versions.
- Verify: Use
node -v
andnpm -v
to confirm installation.