DEV Community

Cover image for How to Install Node.js on Windows, macOS, & Linux
Satyam Gupta
Satyam Gupta

Posted on

How to Install Node.js on Windows, macOS, & Linux

Your Ultimate Guide to Installing Node.js on Windows, macOS, and Linux

So, you've decided to dive into the world of modern web development. You're hearing about building fast servers, real-time applications, and powerful tools, and the name Node.js keeps popping up. But before you can write a single line of that exciting code, you need to get it running on your machine.

If the thought of "installation" makes you nervous, don't worry. You're not alone. Setting up a development environment can feel like a hurdle, but it's a fundamental skill every developer masters. This guide is designed to be the only resource you'll need. We won't just give you commands; we'll explain the why behind them, explore best practices, and answer the questions you're probably asking.

By the end of this article, you'll have Node.js confidently installed on your system, whether it's Windows, macOS, or Linux, and you'll be ready to start building.

What Exactly is Node.js? A Quick Primer
Before we jump into the installation, let's clear up a common misconception. Node.js is not a programming language.

Think of it as a runtime environment. Traditionally, JavaScript was a language that only lived inside your web browser, making web pages interactive. Node.js, created by Ryan Dahl in 2009, took the powerful V8 JavaScript engine from Chrome and let it run on your computer as a standalone program.

This was a game-changer. Suddenly, developers could use JavaScript to write server-side logic, command-line tools, and even desktop applications. This unified a codebase around a single language, streamlining both front-end and back-end development.

Real-World Use Cases of Node.js:

Backend for Web Applications: Powering the server logic for sites like Netflix, LinkedIn, and Uber.

API Servers: Creating fast and scalable REST or GraphQL APIs.

Real-Time Services: Building chat applications, live collaboration tools, and online gaming platforms.

Development Tools: Many of the tools you'll use, like create-react-app or webpack, are built with Node.js.

Scripting and Automation: Writing scripts to automate tedious tasks on your computer.

Understanding this context makes the installation process feel more purposeful. You're not just installing software; you're unlocking a capability. To learn professional software development courses such as Python Programming, Full Stack Development, and MERN Stack (which heavily utilizes Node.js!), visit and enroll today at codercrafter.in.

The Installation Process: A Step-by-Step Guide for Every OS
The best method for installation varies by operating system. We'll cover the most straightforward and recommended approaches for each.

Method 1: Installing Node.js on Windows
Windows users have the most straightforward path.

Download the Installer:

Head to the official Node.js website.

You'll see two versions: LTS and Current. For almost everyone, especially beginners, the LTS (Long Term Support) version is the right choice. It's more stable and widely supported.

Click the Windows Installer (.msi) link for the LTS version.

Run the Installer:

Double-click the downloaded .msi file. You may get a User Account Control prompt; click "Yes."

The Node.js Setup Wizard will open. Click "Next."

Important Step: On the following screen, you'll see the license agreement. Accept it and click "Next." You will now see a custom setup screen. The default installation path is fine. Ensure you check the box that says "Automatically install the necessary tools." This includes Node.js, npm (Node Package Manager), and adds them to your system PATH.

Complete the Installation:

Click "Next" and then "Install." The installer will do its job.

Once finished, click "Finish."

Verify the Installation (The Fun Part!):

Let's make sure everything worked. Press Win + R, type cmd, and hit Enter to open the Command Prompt.

Type the following commands one by one and press Enter:

bash
node --version
npm --version
If the installation was successful, you should see version numbers outputted (e.g., v18.17.0 and 9.6.7). Congratulations! You now have Node.js and npm installed on your Windows machine.

Method 2: Installing Node.js on macOS
For macOS users, you have two excellent options: the official installer or using a package manager like Homebrew.

Option A: Using the Official Installer (Easiest)
Download the macOS Installer:

Go to the Node.js website.

Download the macOS Installer (.pkg) for the LTS version.

Run the Installer:

Open the downloaded .pkg file.

A standard macOS installer will guide you through the process. Just follow the prompts, agreeing to the license and confirming the installation.

You'll likely need to enter your password to allow the installation.

Verify the Installation:

Open the Terminal (you can find it via Spotlight search by pressing Cmd + Space and typing "Terminal").

Type the same verification commands:

bash
node --version
npm --version
You should see the version numbers, confirming a successful install.

Option B: Using Homebrew (Recommended for Developers)
Homebrew is a beloved package manager for macOS that makes installing and managing software a breeze.

Install Homebrew (if you haven't already):

Open your Terminal and paste the installation command from the Homebrew website. It will look something like:

bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Follow the on-screen instructions.

Install Node.js:

Once Homebrew is installed, simply run:

bash
brew install node
Homebrew will handle the rest, downloading and installing Node.js and npm.

Verify the Installation:

Use the same node --version and npm --version commands in your Terminal to confirm.

Method 3: Installing Node.js on Linux
The process on Linux varies slightly depending on your distribution (Ubuntu, Fedora, etc.). We'll cover the method for Ubuntu/Debian-based systems, which is one of the most common.

Using the NodeSource Binary Distributions (Recommended)
The default Ubuntu repositories often have older versions of Node.js. Using the NodeSource repository ensures you get the latest LTS version.

Open Your Terminal.

Add the NodeSource Repository:

First, install curl if you don't have it: sudo apt install curl

Then, fetch and execute the setup script for the desired Node.js version (replace 18.x with the latest LTS version number if different):

bash
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
This command adds the official Node.js repository to your system's sources list.

Install Node.js:

Now, use apt to install Node.js. This will automatically include npm.

bash
sudo apt install nodejs
Verify the Installation:

As always, run our trusty verification commands:

bash
node --version
npm --version
Using a Version Manager (Advanced Best Practice)
For serious development, consider using a version manager like nvm (Node Version Manager). This allows you to install and switch between multiple versions of Node.js seamlessly. This is incredibly useful when working on different projects that require specific Node versions.

Install nvm:

Run the installation script from the nvm GitHub repository:

bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
Close and reopen your Terminal, or run source ~/.bashrc to reload your shell configuration.

Install and Use a Node.js Version:

Install the latest LTS version:

bash
nvm install --lts
Tell nvm to use this version:

bash
nvm use --lts
Verification works the same way! Mastering tools like nvm is a key part of a professional workflow, something we emphasize in the advanced modules at codercrafter.in.

Best Practices and Next Steps After Installation
You've got Node.js running. Now what?

Create Your First Project:

Make a new directory for your project: mkdir my-first-node-app

Navigate into it: cd my-first-node-app

Run npm init -y to create a package.json file, which manages your project's dependencies.

Install a Package:

Let's install the popular axios package for making HTTP requests: npm install axios

Notice a new node_modules folder and a package-lock.json file? This is npm doing its job, managing your project's libraries.

Write a Simple Script:

Create a file called index.js and add this code:

javascript

const axios = require('axios'); // If you are using ES6 modules, you would use 'import'

axios.get('https://api.github.com/users/codercrafter')
  .then(response => {
    console.log(`CoderCrafter's bio: ${response.data.bio}`);
  })
  .catch(error => {
    console.error('Error fetching data:', error);
  });
Enter fullscreen mode Exit fullscreen mode

Run it with: node index.js

You've just run your first Node.js script!

Frequently Asked Questions (FAQs)
Q: What's the difference between node and npm?
A: node is the runtime itself—the engine that executes your JavaScript code. npm is the Node Package Manager, a massive registry of open-source code libraries (packages) that you can easily install and use in your projects.

Q: Should I install the LTS or Current version?
A: Always start with LTS for production or serious development. The "Current" version contains the latest features but might be less stable. It's for experimentation.

Q: I'm getting a permission error on Linux/macOS when using npm install -g. What do I do?
A: This is common. Never use sudo with npm install as it can lead to security issues and file permission chaos. Instead, change npm's default directory to one you own. The official npm docs have a great guide on this.

Q: How do I update Node.js to a newer version?
A: On Windows and macOS, the easiest way is to re-download the installer from the official website and run it. It will cleanly upgrade your existing version. If you used nvm on Linux/macOS, simply run nvm install --lts and nvm use --lts again.

Conclusion: Your Development Journey Starts Now
Installing Node.js is the first concrete step on a path to building incredible things on the web. You've equipped your machine with a powerful tool used by millions of developers and companies worldwide. The process might seem technical now, but soon it will be second nature.

Remember, this is just the beginning. The real magic happens when you start combining Node.js with frameworks like Express.js, databases like MongoDB, and front-end libraries like React. This entire ecosystem is what constitutes the powerful MERN Stack, a cornerstone of modern full-stack development.

If you're excited by this and want to move beyond setup guides to building real-world, portfolio-ready applications, we can help you structure that journey. To learn professional software development courses such as Python Programming, Full Stack Development, and MERN Stack, visit and enroll today at codercrafter.in.

Top comments (0)