Introduction
Node.js is a powerful JavaScript runtime environment that enables you to run JavaScript code on the server side. npm (Node Package Manager) is the default package manager for Node.js and is essential for managing JavaScript packages and dependencies. In this guide, we’ll walk you through the steps to install Node.js and npm on Windows, macOS, and Linux.
1. Installing Node.js and npm on Windows
Step 1: Download Node.js
- Visit the Node.js official website.
- Download the Windows Installer (.msi) for the LTS (Long Term Support) version.
Step 2: Install Node.js
- Run the downloaded .msi file.
- Follow the installation prompts, ensuring that you check the box to include npm in the installation.
- Click “Next” and “Install” to complete the setup.
Step 3: Verify the Installation
- Open Command Prompt.
- Type node -v to check the Node.js version.
- Type npm -v to check the npm version.
2. Installing Node.js and npm on macOS
Step 1: Install Node.js via Homebrew
- Open Terminal.
- Install Homebrew if you haven’t already by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3.Install Node.js and npm with:
brew install node
Step 2: Verify the Installation
- In Terminal, type node -v to check the Node.js version.
- Type npm -v to check the npm version.
Alternative Method: Download from the Website
- Visit the Node.js official website.
- Download the macOS installer and run the .pkg file.
- Follow the prompts to complete the installation.
3. Installing Node.js and npm on Linux
Step 1: Update Your Package Index
- Open Terminal.
- Run the following command to update the package index:
sudo apt update
Step 2: Install Node.js and npm
- For Debian/Ubuntu-based distributions:
sudo apt install nodejs npm - For CentOS/RHEL-based distributions:
sudo yum install nodejs npm - For Fedora:
sudo dnf install nodejs npm
Step 3: Verify the Installation
- In Terminal, type node -v to check the Node.js version.
- Type npm -v to check the npm version.
Alternative Method: Install via Node Version Manager (nvm)
- Install nvm (Node Version Manager) by running:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
- Load nvm:
source ~/.bashrc
- Install Node.js using nvm:
nvm install node
- Verify by typing node -v and npm -v.
Conclusion
Installing Node.js and npm is straightforward, whether you’re on Windows, macOS, or Linux. By following this guide, you’ll have Node.js and npm up and running in no time, ready for your development projects. With Node.js installed, you’re all set to explore the world of server-side JavaScript and start building powerful applications.