Windows、macOS、LinuxにNode.jsとnpmをインストールする方法

8月 23, 2024

はじめに

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. Installing Node.js and npm on Windows

Step 1: Download Node.js

  1. Visit the Node.js official website.
  2. Download the Windows Installer (.msi) for the LTS (Long Term Support) version.

Step 2: Install 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.

Step 3: Verify the Installation

  1. Open Command Prompt.
  2. タイプ node -v to check the Node.js version.
  3. タイプ npm -v to check the npm version.

2. Installing Node.js and npm on macOS

Step 1: Install Node.js via Homebrew

  1. Open Terminal.

  1. Install 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

Step 2: Verify the Installation

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

Alternative Method: Download from the Website

  1. Visit the Node.js official website.
  2. Download the macOS installer and run the .pkg file.
  3. Follow the prompts to complete the installation.

3. Installing Node.js and npm on Linux

Step 1: Update Your Package Index

  1. Open Terminal.

  1. Run the following command to update the package index:
    sudo apt update

Step 2: Install Node.js and npm

  • For Debian/Ubuntu-based distributions:
    sudo apt install nodejs npm

  • For CentOS/RHEL-based distributions:
    sudo yum install nodejs npm

  • For Fedora:
    sudo dnf install nodejs npm

Step 3: Verify the Installation

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

Alternative Method: Install via Node Version Manager (nvm)

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

結論

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 and start building powerful アプリケーション.

jaJapanese