You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today.

How to Install Node.js on Your System

Node.js is a popular runtime environment that allows developers to run JavaScript on the server side. It's widely used for building scalable network applications, real-time apps, and command-line tools. Installing Node.js on your system is a straightforward process, and this guide will walk you through how to do it step-by-step for various operating systems.

Why Install Node.js?

Before we dive into the installation process, it’s worth understanding why you might want to install Node.js. It allows you to:

  • Run JavaScript on the server side.
  • Manage project dependencies via npm (Node Package Manager).
  • Build web servers, command-line tools, and other backend applications.
  • Use frameworks like Express.js to create web applications.

Prerequisites

  • You’ll need an internet connection to download the necessary installation files.
  • Basic knowledge of the terminal or command prompt in your operating system.

Installing Node.js on Windows

Step 1: Download Node.js

  1. Open a web browser and navigate to the official Node.js website.
  2. On the homepage, you’ll see two versions available for download:
    • LTS (Long Term Support): This is the recommended version for most users.
    • Current: This version has the latest features but may not be as stable.
  3. Click on the LTS version to download the installer.

Step 2: Install Node.js

  1. Once the installer is downloaded, double-click the .msi file to start the installation process.
  2. The Node.js Setup Wizard will guide you through the installation. You can accept the default options unless you have specific preferences.
  3. During the installation, make sure that the Add to PATH option is checked. This will allow you to use Node.js from the command prompt.
  4. Click Next, and once the installation is complete, click Finish.

Step 3: Verify Installation

  1. Open a command prompt by searching for “cmd” in the start menu.

  2. Type the following command to check the installed Node.js version:

    node -v
    

    You should see the version of Node.js installed.

  3. Also, check for npm (Node Package Manager), which is installed along with Node.js:

    npm -v
    

Installing Node.js on macOS

Step 1: Download Node.js

  1. Visit the official Node.js website using Safari or another browser.
  2. Download the LTS version for macOS by clicking the macOS installer.

Step 2: Install Node.js

  1. Once the .pkg file is downloaded, double-click it to start the installation.
  2. Follow the on-screen instructions, accepting the default options.
  3. The installer will automatically install both Node.js and npm.

Step 3: Verify Installation

  1. Open the Terminal application (you can search for it in Spotlight).

  2. Type the following command to check the version of Node.js:

    node -v
    

    You should see the version number of Node.js.

  3. Check the npm version by running:

    npm -v
    

Installing Node.js on Linux

Step 1: Using Package Manager (Debian/Ubuntu)

  1. Open a terminal window.
  2. First, update your package index:
    sudo apt update
    
  3. Install Node.js using the following command:
    sudo apt install nodejs
    
  4. Install npm (if it is not installed with Node.js by default):
    sudo apt install npm
    

Step 2: Verify Installation

  1. Check the version of Node.js:
    node -v
    
  2. Check npm version:
    npm -v
    

Step 3: (Optional) Install Node.js via NodeSource (For Latest Version)

  1. If you want the latest version of Node.js, you can use NodeSource to install it:
    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    Replace 16.x with the version you need (e.g., 18.x for the latest LTS version).

Installing Node.js via nvm (Node Version Manager)

If you want the flexibility of managing multiple versions of Node.js on your system, you can install nvm (Node Version Manager).

Step 1: Install nvm

  1. Open your terminal.
  2. Install nvm by running the following command:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    
  3. Close and reopen your terminal or run the following command to load nvm:
    source ~/.bashrc
    

Step 2: Install Node.js Using nvm

  1. Install the latest LTS version of Node.js:
    nvm install --lts
    
  2. You can check which version of Node.js is active by typing:
    nvm current
    

Step 3: Switch Between Versions

  1. If you want to switch between different versions of Node.js, simply run:
    nvm use 16
    
    Or, replace 16 with the desired version.

Conclusion

Congratulations! You’ve successfully installed Node.js on your system. You can now start developing server-side JavaScript applications and make use of npm to manage dependencies for your projects.

Next Steps:

  • Explore Node.js documentation and tutorials to learn how to build web servers and other applications.
  • Use npm to install popular frameworks like Express.js or tools like Webpack to enhance your development experience.

Happy coding!