How to Install Nodejs

How to Install Node.js: A Complete Step-by-Step Guide for Developers Node.js has become one of the most essential tools in modern web development. Built on Chrome’s V8 JavaScript engine, Node.js allows developers to run JavaScript on the server side, enabling seamless full-stack development using a single language. Its event-driven, non-blocking I/O model makes it exceptionally efficient for build

Nov 6, 2025 - 11:07
Nov 6, 2025 - 11:07
 2

How to Install Node.js: A Complete Step-by-Step Guide for Developers

Node.js has become one of the most essential tools in modern web development. Built on Chromes V8 JavaScript engine, Node.js allows developers to run JavaScript on the server side, enabling seamless full-stack development using a single language. Its event-driven, non-blocking I/O model makes it exceptionally efficient for building scalable network applications from real-time chat platforms to RESTful APIs and microservices.

Whether you're a beginner taking your first steps into backend development or an experienced engineer setting up a new machine, installing Node.js correctly is the foundational step toward unlocking its full potential. A poorly configured installation can lead to dependency conflicts, version mismatches, or permission issues that waste hours of development time.

This comprehensive guide walks you through every aspect of installing Node.js across major operating systems Windows, macOS, and Linux with clear, tested instructions. Youll also learn best practices for managing multiple versions, optimizing your environment, and avoiding common pitfalls. By the end of this tutorial, youll have a robust, production-ready Node.js setup that supports professional development workflows.

Step-by-Step Guide

Installing Node.js on Windows

Installing Node.js on Windows is one of the most straightforward processes, thanks to the official installer provided by the Node.js Foundation.

  1. Visit the official Node.js website at https://nodejs.org.
  2. On the homepage, youll see two version options: LTS (Long-Term Support) and Current. For most users, especially those new to Node.js, select the LTS version. It offers the highest stability and is recommended for production environments.
  3. Click the download button for the Windows Installer (.msi). The file size is typically under 20 MB.
  4. Once the download completes, locate the .msi file in your Downloads folder and double-click to launch the installer.
  5. The Node.js Setup Wizard will open. Click Next to proceed through the welcome screen.
  6. Review the license agreement, check the box to accept it, and click Next.
  7. Choose the installation location. The default path (usually C:\Program Files\nodejs\) is recommended unless you have specific requirements. Click Next.
  8. Select the components to install. The default options Node.js runtime, npm package manager, and optional tools are sufficient for 99% of users. Do not uncheck these unless you have advanced needs. Click Next.
  9. Click Install to begin the installation. You may see a User Account Control (UAC) prompt click Yes to allow the installer to make changes.
  10. Wait for the progress bar to complete. This typically takes less than a minute.
  11. When the installation finishes, click Finish.

To verify the installation, open the Command Prompt (search for cmd in the Start menu) and type:

node --version

npm --version

If both commands return version numbers (e.g., v20.12.0 and 10.5.0), Node.js and npm are installed correctly.

Installing Node.js on macOS

macOS users have multiple options for installing Node.js: using the official installer, Homebrew, or version managers like nvm. We recommend using nvm (Node Version Manager) for its flexibility and version control capabilities, especially if you work on multiple projects requiring different Node.js versions.

Option 1: Install Node.js Using nvm (Recommended)

  1. Open Terminal. You can find it via Spotlight Search (Cmd + Space, then type Terminal).
  2. Install nvm by running the following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

If youre using a different shell like Zsh (default on macOS Catalina and later), you may need to restart your terminal or run:

source ~/.zshrc

To confirm nvm installed correctly, run:

nvm --version

You should see a version number (e.g., 0.39.7).

  1. Install the latest LTS version of Node.js:
nvm install --lts

  1. Set the installed LTS version as default:
nvm use --lts

nvm alias default node

  1. Verify the installation:
node --version

npm --version

You should now see the latest LTS version number for both Node.js and npm.

Option 2: Install Node.js Using the Official Installer

If you prefer a graphical installer:

  1. Visit https://nodejs.org and download the macOS Installer (.pkg) for the LTS version.
  2. Open the downloaded .pkg file and follow the on-screen instructions.
  3. Click Continue, accept the license, choose your disk, and click Install.
  4. Enter your macOS password when prompted.
  5. After installation, restart Terminal and run node --version and npm --version to confirm.

Installing Node.js on Linux (Ubuntu/Debian)

Linux distributions offer several methods to install Node.js. Well cover two reliable approaches: using the official NodeSource repository and using nvm.

Option 1: Install Node.js via NodeSource Repository

  1. Open a terminal window.
  2. Update your package list:
sudo apt update

  1. Install curl if its not already installed:
sudo apt install curl -y

  1. Add the NodeSource repository for the latest LTS version (currently Node.js 20.x):
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

  1. Install Node.js:
sudo apt install nodejs -y

  1. Verify the installation:
node --version

npm --version

On some Linux systems, the node command may conflict with another package. If you receive an error, try:

nodejs --version

If the version displays correctly, create a symbolic link to make node work:

sudo ln -s /usr/bin/nodejs /usr/bin/node

Option 2: Install Node.js Using nvm (Recommended for Developers)

nvm is ideal for Linux developers who need to switch between Node.js versions frequently.

  1. Open Terminal.
  2. Install nvm with:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

  1. Reload your shell configuration:
source ~/.bashrc

If youre using Zsh, use:

source ~/.zshrc

  1. Install the LTS version:
nvm install --lts

  1. Set it as default:
nvm use --lts

nvm alias default node

  1. Verify:
node --version

npm --version

Best Practices

Use Node Version Manager (nvm) for Development

One of the most important best practices for Node.js developers is to use nvm. Unlike system-wide installations, nvm allows you to install and switch between multiple Node.js versions seamlessly. This is critical when working on legacy projects that require Node.js 16 or 18, while building new applications with Node.js 20.

With nvm, you can:

  • Install any Node.js version with a single command: nvm install 18.18.0
  • Switch between versions: nvm use 18.18.0
  • List installed versions: nvm ls
  • Set a default version for new terminals: nvm alias default 20.12.0

Never install Node.js globally using sudo on macOS or Linux unless absolutely necessary. Doing so can cause permission conflicts and break npm packages.

Always Use the LTS Version in Production

Node.js releases two types of versions: Current and LTS. The Current version includes the latest features but may contain bugs or breaking changes. The LTS version is thoroughly tested, receives long-term security updates, and is supported for 30 months.

For any production deployment whether on a VPS, cloud server, or container always use the latest LTS version. Avoid using Current unless youre actively testing new features in a development environment.

Keep npm and Node.js Updated

npm (Node Package Manager) is updated frequently to fix security vulnerabilities and improve performance. Regularly update npm using:

npm install -g npm@latest

Also, periodically check for new Node.js LTS releases using:

nvm ls-remote

Then upgrade your default version with:

nvm install --lts --reinstall-packages-from=current

This command installs the latest LTS version and reinstalls all globally installed packages from your previous version.

Configure npm Global Directory to Avoid Permission Issues

On macOS and Linux, installing global packages with sudo is discouraged because it can interfere with system files. Instead, configure npm to use a user-owned directory:

  1. Create a directory for global packages:
mkdir ~/.npm-global

  1. Configure npm to use it:
npm config set prefix '~/.npm-global'

  1. Add the directory to your shell profile. For Bash:
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc

source ~/.bashrc

For Zsh:

echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc

source ~/.zshrc

Now you can install global packages without sudo:

npm install -g nodemon

Use a .nvmrc File for Project-Specific Node Versions

For team-based projects, create a .nvmrc file in your project root to specify the required Node.js version:

echo "20.12.0" > .nvmrc

Then, anyone who clones the project can simply run:

nvm use

nvm will automatically detect and switch to the version specified in .nvmrc, ensuring consistency across development environments.

Enable npm Audit and Use Security Tools

Run regular security audits on your project dependencies:

npm audit

This command scans your package-lock.json for known vulnerabilities and suggests fixes. For automated security scanning, consider integrating tools like Snyk or GitHub Dependabot into your CI/CD pipeline.

Tools and Resources

Essential Tools for Node.js Development

Once Node.js is installed, these tools will significantly enhance your productivity:

  • npm The default package manager for Node.js. Used to install, update, and manage libraries.
  • npx A tool that comes with npm 5.2+. Allows you to run packages without installing them globally. Example: npx create-react-app my-app.
  • nodemon Automatically restarts your Node.js server when file changes are detected. Install globally: npm install -g nodemon.
  • Visual Studio Code The most popular code editor for JavaScript development. Install the official JavaScript and Node.js extensions for syntax highlighting, debugging, and IntelliSense.
  • Postman A powerful API testing tool for testing HTTP endpoints created with Express.js or other Node.js frameworks.
  • Insomnia A lightweight, open-source alternative to Postman.
  • pm2 A production process manager for Node.js applications. Ensures your app stays running and restarts on crashes.

Official and Trusted Resources

Always refer to official documentation and trusted sources to avoid outdated or malicious tutorials:

Learning Resources

Expand your knowledge with these curated resources:

  • FreeCodeCamps Node.js Course Free, project-based curriculum on YouTube and their website.
  • The Net Ninjas Node.js Tutorial Series Beginner-friendly video tutorials on YouTube.
  • Node.js Design Patterns (Book) by Mario Casciaro Deep dive into architecture and scalable patterns.
  • Mastering Node.js (Book) by Sergio Xalambr Advanced topics including clustering, streams, and performance optimization.

Development Environment Checklist

Before starting a new Node.js project, ensure your environment is properly configured:

  • Node.js LTS installed via nvm
  • npm updated to latest version
  • Global packages installed without sudo
  • VS Code with recommended extensions
  • Terminal configured with auto-completion for npm and nvm
  • Git installed and configured with your username/email
  • Project folder structure planned (e.g., src/, config/, tests/)

Real Examples

Example 1: Setting Up a Basic Express Server

After installing Node.js, create a simple web server using Express.js one of the most popular Node.js frameworks.

  1. Create a new project folder:
mkdir my-express-app

cd my-express-app

  1. Initialize a new Node.js project:
npm init -y

  1. Install Express:
npm install express

  1. Create a file named server.js with the following content:
const express = require('express');

const app = express();

const port = 3000;

app.get('/', (req, res) => {

res.send('Hello, Node.js!');

});

app.listen(port, () => {

console.log(Server running at http://localhost:${port});

});

  1. Run the server:
node server.js

Open your browser and navigate to http://localhost:3000. You should see Hello, Node.js! displayed.

Example 2: Using nvm to Switch Versions Between Projects

Suppose you have two projects:

  • legacy-project Requires Node.js 16.x
  • new-project Built with Node.js 20.x

Install both versions using nvm:

nvm install 16.20.2

nvm install 20.12.0

In each project folder, create a .nvmrc file:

In legacy-project/

echo "16.20.2" > .nvmrc

In new-project/

echo "20.12.0" > .nvmrc

When you navigate into each folder and run nvm use, nvm automatically switches to the correct version:

cd legacy-project

nvm use

Output: Now using node v16.20.2 (npm v8.19.4)

cd ../new-project

nvm use

Output: Now using node v20.12.0 (npm v10.5.0)

This eliminates version conflicts and ensures every team member uses the exact same runtime.

Example 3: Deploying a Node.js App with pm2

After testing your app locally, deploy it to a server using pm2 for process management.

  1. Install pm2 globally:
npm install -g pm2

  1. Start your app with pm2:
pm2 start server.js --name "my-app"

  1. Check the status:
pm2 list

  1. Enable auto-start on system reboot:
pm2 startup

pm2 save

Now your Node.js application runs in the background, restarts on crash, and survives server reboots a critical requirement for production environments.

FAQs

Can I install Node.js without administrator privileges?

Yes. On Windows, you can use the ZIP archive version and extract it to a user directory. On macOS and Linux, using nvm is the best way to install Node.js without sudo. nvm installs Node.js in your home directory, requiring no elevated permissions.

Whats the difference between Node.js and JavaScript?

JavaScript is a programming language. Node.js is a runtime environment that allows JavaScript to execute outside the browser specifically on servers. Node.js includes the V8 engine and additional libraries for file system access, networking, and more.

Do I need to install Python or Visual Studio to use Node.js?

On Windows, some npm packages require native compilation (e.g., bcrypt, node-sass). These may require Python and build tools. To avoid this, use npm install --global windows-build-tools or install Visual Studio Build Tools. On macOS and Linux, this is rarely needed.

Why does npm install packages in a different location than I expected?

npm installs global packages in a directory defined by its prefix setting. Run npm config get prefix to see where global packages are installed. Use nvm or reconfigure the prefix to control this location.

How do I uninstall Node.js completely?

On macOS/Linux with nvm: nvm uninstall node removes all versions. On Windows: Use the Programs and Features control panel to uninstall Node.js. Also delete the C:\Program Files\nodejs folder and remove any Node.js entries from your PATH environment variable.

Is it safe to use Node.js 21.x (Current)?

Only for development and experimentation. Node.js Current versions are not recommended for production. They are supported for only 6 months and may contain unstable features. Always use the latest LTS version in production.

What should I do if I get a command not found error after installing Node.js?

This usually means the installation path is not in your systems PATH environment variable. Restart your terminal, or manually add the Node.js path. For nvm users, ensure the nvm initialization script is loaded in your shell profile (.bashrc, .zshrc, etc.).

Can I run Node.js on a Raspberry Pi?

Yes. Node.js supports ARM architectures. Download the ARM binary from nodejs.org or use nvm. For Raspberry Pi OS, run: nvm install --lts after installing nvm.

How do I check if my Node.js installation is corrupted?

Run node -e "console.log('Hello World!')". If it outputs Hello World!, your installation is functional. If you get errors, reinstall using nvm or the official installer.

Do I need to restart my computer after installing Node.js?

No. However, you should restart your terminal or command prompt to refresh the PATH variable. If you used nvm, reload your shell profile with source ~/.bashrc or source ~/.zshrc.

Conclusion

Installing Node.js is a simple process, but doing it correctly with version control, proper permissions, and a scalable environment is what separates casual users from professional developers. By following the steps outlined in this guide, youve not only installed Node.js; youve set up a development environment built for reliability, collaboration, and long-term maintainability.

Using nvm ensures you can work across multiple projects with different Node.js requirements. Configuring npms global directory avoids permission headaches. Choosing the LTS version guarantees stability in production. And tools like nodemon, pm2, and VS Code turn your setup into a powerful development ecosystem.

As you continue your journey with Node.js, remember that the ecosystem evolves rapidly. Stay updated with new releases, learn to read official documentation, and never hesitate to test changes in isolated environments before deploying them.

With a solid foundation now in place, youre ready to build dynamic APIs, real-time applications, and scalable microservices. The world of server-side JavaScript is open to you start coding, experiment boldly, and build something remarkable.