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
- Käy osoitteessa Node.js virallinen verkkosivusto.
- Lataa Windows-asennusohjelma (.msi) LTS-versiota (Long Term Support) varten.
Vaihe 2: Asenna 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.
Vaihe 3: Asennuksen tarkistaminen
- Avaa komentorivi.
- Type node -v to check the Node.js version.
- 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
- Avaa terminaali.
- Asenna Homebrew if you haven’t already by running:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install Node.js and npm with:
brew install node
Vaihe 2: Asennuksen tarkistaminen
- In Terminal, type node -v to check the Node.js version.
- Type npm -v to check the npm version.
Vaihtoehtoinen menetelmä: Lataa verkkosivustolta
- Käy osoitteessa Node.js virallinen verkkosivusto.
- Download the macOS installer and run the .pkg file.
- Suorita asennus loppuun noudattamalla kehotteita.
3. Node.js:n ja npm:n asentaminen Linuxiin
Vaihe 1: Päivitä paketti-indeksi
- Avaa terminaali.
- 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
- In Terminal, type node -v to check the Node.js version.
- Type npm -v to check the npm version.
Vaihtoehtoinen menetelmä: Asenna Node Version Managerin (nvm) kautta.
- 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.
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.