Installing Node.js & npm ยท Astro Tech Blog

Installation Options

There are three ways to install Node.js:

MethodBest ForNotes
Official installerBeginnersDownload from nodejs.org
Package managerSystem-wide installapt, brew, choco
Version manager (nvm)Developers switching versionsMost flexible

Method 1: Official Installer

Go to nodejs.org and download the LTS version (recommended for most users) or Current (latest features).

nodejs.org
    โ”‚
    โ”œโ”€โ”€ LTS (e.g., 22.x) โ€” stable, production-ready
    โ””โ”€โ”€ Current (e.g., 24.x) โ€” latest V8, experimental APIs

After installation, verify:

node --version
# v22.x.x

npm --version
# 10.x.x

Method 2: Package Manager

macOS (Homebrew)

brew install node

Linux (Ubuntu/Debian)

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

Windows (winget)

winget install OpenJS.NodeJS.LTS

nvm (Node Version Manager) lets you install and switch between multiple Node.js versions:

# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# Restart terminal, then:
nvm install 22       # Install latest v22
nvm install 20       # Install latest v20
nvm use 22           # Switch to v22
nvm default 22       # Set v22 as default

Pro tip: With nvm, you can test your code against multiple Node.js versions in seconds.

What Gets Installed?

When you install Node.js, you get three things:

/usr/local/bin/
โ”œโ”€โ”€ node          # The JavaScript runtime
โ”œโ”€โ”€ npm           # Package manager
โ””โ”€โ”€ npx           # Run npm packages without installing

Verify all three:

node -e "console.log('Node works')"
npm help
npx --version

Your First Node.js Project

# Create a project directory
mkdir my-first-app
cd my-first-app

# Create a file
echo 'console.log("Node.js is ready!");' > index.js

# Run it
node index.js

Updating Node.js

MethodCommand
nvmnvm install 22 --reinstall-packages-from=20
macOS Homebrewbrew upgrade node
Linux (nodesource)sudo apt-get upgrade nodejs
WindowsRe-run the installer

Uninstalling Node.js

# nvm
nvm uninstall 22

# macOS Homebrew
brew uninstall node

# Ubuntu/Debian
sudo apt-get remove nodejs

Key Takeaways

  • Use the official installer for a quick start
  • Use nvm if you switch between Node.js versions
  • node --version and npm --version verify the installation
  • Node.js ships with node, npm, and npx out of the box
  • Always prefer the LTS version for production