How to Install Node.js and npm on Windows, macOS & Linux (2025 Guide)

August 23, 2024

Johdanto

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. Node.js:n ja npm:n asentaminen Windowsissa

Vaihe 1: Lataa Node.js

  1. Käy osoitteessa Node.js virallinen verkkosivusto.
  2. Lataa Windows-asennusohjelma (.msi) LTS-versiota (Long Term Support) varten.

Vaihe 2: Asenna Node.js

  1. Run the downloaded .msi file.
  2. Follow the installation prompts, ensuring that you check the box to include npm in the installation.
  3. Click “Next” and “Install” to complete the setup.

Vaihe 3: Asennuksen tarkistaminen

  1. Avaa komentorivi.
  2. Type node -v to check the Node.js version.
  3. Type npm -v to check the npm version.

2. Node.js:n ja npm:n asentaminen macOS:lle

Vaihe 1: Asenna Node.js Homebrew:n kautta

  1. Avaa terminaali.
  2. Asenna 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

Vaihe 2: Asennuksen tarkistaminen

  1. In Terminal, type node -v to check the Node.js version.
  2. Type npm -v to check the npm version.

Vaihtoehtoinen menetelmä: Lataa verkkosivustolta

  1. Käy osoitteessa Node.js virallinen verkkosivusto.
  2. Download the macOS installer and run the .pkg file.
  3. Suorita asennus loppuun noudattamalla kehotteita.

3. Node.js:n ja npm:n asentaminen Linuxiin

Vaihe 1: Päivitä paketti-indeksi

  1. Avaa terminaali.
  2. Suorita seuraava komento päivittääksesi paketti-indeksin:
    sudo apt update

Vaihe 2: Asenna Node.js ja npm

  • Debian/Ubuntu-pohjaisille jakeluille:
    sudo apt install nodejs npm
  • CentOS/RHEL-pohjaisille jakeluille:
    sudo yum install nodejs npm
  • Fedoran osalta:
    sudo dnf install nodejs npm

Vaihe 3: Asennuksen tarkistaminen

  1. In Terminal, type node -v to check the Node.js version.
  2. Type npm -v to check the npm version.

Vaihtoehtoinen menetelmä: Asenna Node Version Managerin (nvm) kautta.

  1. Install nvm (Node Version Manager) by running:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
  2. Load nvm:
    source ~/bashrc
  3. Install Node.js using nvm:
    nvm install node
  4. Verify by typing node -v and npm -v.

Johtopäätös

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 ja alkaa rakentaa tehokkaita sovellukset.