Site logo
Authors
  • avatar Nguyễn Đức Xinh
    Name
    Nguyễn Đức Xinh
    Twitter
Published on
Published on

Installation NodeJS and NPM on MacOS, Window and Linux

Node.js and NPM are two essential tools for modern web development. Node.js (Cross-platform Runtime Environment) provides a server-side JavaScript runtime, while NPM (Node Package Manager) is a powerful library and package management tool. This guide will walk you through how to easily install Node.js and NPM.

Preparation Steps

Before starting, ensure you have:

  • A computer running Windows , macOS , or Linux .
  • An internet connection to download the installation packages.

How to Check Node.js Before Installation

To check whether Node.js is already installed on your system, open the Command Prompt (Windows) or Terminal (macOS/Linux) and type the following command:

node -v

If Node.js is installed, the current version will be displayed. If not, proceed with the steps below to install it.

Installation Guide for Node.js and NPM

1. Download Node.js

Visit the official Node.js website at https://nodejs.org and download the appropriate version:

  • LTS (Long-Term Support) : Stable and suitable for most projects.
  • Current : The latest version, for those who want access to the newest features.

2. Installing Node.js on Windows

  1. Open the downloaded installer file (with the .msi extension).
  2. Follow the on-screen instructions:
  • Agree to the terms and conditions.
  • Select the default settings (recommended ).
  1. Click Install and wait for the installation to complete. After installation, verify the Node.js and NPM versions:
node -v
npm -v

3. Installing Node.js on macOS

  1. Use Homebrew to install Node.js: If Homebrew is not installed, install it using the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install Node.js with Homebrew:
brew install node
# Or
brew install node@22
  1. Verify the installed version:
node -v
# v22.12.0
npm -v
# 10.9.0

4. Installing Node.js on Linux

4.1 For Ubuntu

  1. Update the package list:
sudo apt update -y
  1. Install Node.js and NPM:
sudo apt install nodejs npm -y
  1. Verify the version:
node -v
# v18.19.1

npm -v
# 9.2.0

For newer versions, use nodesource :

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash -
sudo apt-get install nodejs -y

4.2 For AmazonLinux 2023

  1. Update the package list:
sudo dnf update -y
sudo dnf upgrade -y
  1. Install Node.js and NPM:
sudo dnf install nodejs -y
# Or install a specific version
sudo dnf install nodejs20 -y
  1. Verify the version:
node -v
# v20.18.0
npm -v
# 10.8.2

Managing Node.js Versions with NVM (Node Version Manager)

If you need to use multiple versions of Node.js, install Node Version Manager (NVM) :

  1. Install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
  1. Configure the NVM Path:
# For bash
source ~/.bashrc

# For zsh
source ~/.zshrc
  1. Check the NVM version:
nvm --version
# 0.40.0
  1. Install Node.js using NVM:
nvm install 22
nvm use 22
  1. Verify the version:
node -v
# v22.12.0
npm -v
# 10.9.0

Conclusion

Installing Node.js and NPM is simple, allowing you to quickly start developing modern JavaScript applications. Choose the version that best suits your application. Note that we recommend using newer versions and LTS (Long Term Support) support to ensure good performance and security.