15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started
18.10.2024

How to Install Node.js: A Complete Technical Guide for All Platforms

Node.js is an open-source, cross-platform JavaScript runtime built on Chrome's V8 engine that executes JavaScript code outside a browser environment. Its non-blocking, event-driven I/O model makes it the dominant choice for building high-throughput APIs, real-time applications, microservices, and server-side tooling. Installing Node.js correctly — using the right method for your OS and workflow — is the foundation of a stable, reproducible development environment.

This guide covers every major installation path: official installers, OS-native package managers, the NodeSource binary distributions, and nvm (Node Version Manager). It also addresses version management, global package hygiene, and production-server considerations that most tutorials skip entirely.

Choosing the Right Installation Method

Before running a single command, understand what each method actually gives you — because the wrong choice creates real operational problems later.

MethodBest ForVersion FlexibilityRoot RequiredNotes
Official `.pkg` / `.msi` installerQuick local setup, beginnersSingle version onlyYesPollutes system PATH; hard to switch versions
OS package manager (`apt`, `brew`, `yum`)System-wide installs, CI serversLimitedYesOften ships outdated versions
NodeSource binary repoLinux servers, predictable LTS pinningPer-installYesMaintained by NodeSource; good for production
`nvm` (Node Version Manager)Multi-project developmentFull, per-shellNoGold standard for developer workstations
`fnm` (Fast Node Manager)Performance-sensitive CI pipelinesFullNoRust-based, significantly faster than nvm
Docker / container imageIsolated, reproducible buildsFull, per-containerDependsBest for microservices and CI/CD

Key decision rule: On a developer workstation, always use nvm or fnm. On a production Linux server, use the NodeSource repository or a container image. Never use the OS default package manager's Node.js package on Ubuntu/Debian — it routinely ships versions that are years behind current LTS.

Installing Node.js on Linux

Linux is where most Node.js production workloads actually run. Getting this right matters more here than anywhere else. If you are deploying to a VPS Hosting environment, the following methods apply directly to your remote server.

NodeSource maintains up-to-date, signed .deb and .rpm packages that track Node.js LTS and Current release lines precisely. This is the most reliable approach for production Linux servers.

Ubuntu / Debian:

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

Fedora / CentOS / RHEL / Rocky Linux:

curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs

After installation, verify both the runtime and the bundled package manager:

node -v
npm -v

Critical pitfall: The curl | bash pattern executes a remote script as root. In security-sensitive environments, download the script first, inspect it, then execute it:

curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
less nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install -y nodejs

nvm installs Node.js entirely in your home directory (~/.nvm), requires no sudo, and lets you switch versions per project or per shell session. This is the correct tool for any workstation or multi-tenant server where different applications require different Node.js versions.

Install nvm:

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

The installer appends the necessary shell initialization to ~/.bashrc, ~/.zshrc, or ~/.profile. Reload your shell:

source ~/.bashrc

Install the latest LTS release:

nvm install --lts

Install a specific version by number:

nvm install 20.14.0

Switch between installed versions:

nvm use 18
nvm use 20

Set a persistent default for new shell sessions:

nvm alias default 20

List all locally installed versions:

nvm ls

Verify the active version:

node -v
npm -v

Edge case — .nvmrc files: Place a .nvmrc file in your project root containing just the version string (e.g., 20.14.0). Running nvm use inside that directory automatically selects the correct version. This is essential for team environments where version drift causes subtle bugs.

echo "20.14.0" > .nvmrc
nvm use

Method 3: System Package Manager (Acceptable for Tooling, Not Production)

The default apt or dnf repositories ship Node.js versions that are frequently outdated. Use this only for non-critical tooling:

sudo apt-get update
sudo apt-get install -y nodejs npm

On Fedora / RHEL 9+:

sudo dnf install nodejs

Installing Node.js on macOS

Homebrew is the de facto package manager for macOS development environments. If Homebrew is not yet installed, follow the instructions at brew.sh.

brew install node

To install a specific major version (e.g., Node.js 20 LTS):

brew install node@20
brew link --overwrite node@20

Verify:

node -v
npm -v

Homebrew pitfall: brew upgrade node will upgrade to the latest version, which may break projects pinned to an older release. If you manage multiple projects, use nvm on macOS as well — the workflow is identical to Linux.

Method 2: nvm on macOS

The nvm installation and usage commands are identical to Linux. macOS users with Zsh (the default since Catalina) should confirm that ~/.zshrc contains the nvm initialization block after installation:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"

Method 3: Official .pkg Installer

Download the .pkg installer from nodejs.org, run it, and follow the wizard. This is the simplest path for users who need a single Node.js version and have no plans to switch. After installation, open Terminal and confirm:

node -v
npm -v

Installing Node.js on Windows

Method 1: Official .msi Installer

Download the Windows installer (.msi) from nodejs.org. Select the LTS build for production-adjacent work or Current for experimenting with the latest features. The installer registers Node.js in the system PATH automatically.

After installation, open Command Prompt or PowerShell and verify:

node -v
npm -v

Important: During the installer wizard, there is an optional step to install Chocolatey and build tools for native modules (C++ addons). Enable this if your project dependencies include packages like bcrypt, sharp, or node-gyp-dependent modules. Skipping it causes cryptic build failures later.

Method 2: Chocolatey

Chocolatey is a Windows package manager that enables scripted, repeatable installations — valuable for developer machine provisioning.

Open an elevated (Administrator) Command Prompt or PowerShell:

choco install nodejs-lts

Verify:

node -v
npm -v

Method 3: nvm-windows

Note that nvm for Linux/macOS does not run on Windows. The Windows equivalent is nvm-windows, a separate project with a similar interface.

Download the installer from the nvm-windows GitHub releases page. After installation:

nvm install lts
nvm use lts
node -v

Windows Subsystem for Linux (WSL2): Developers doing serious Node.js work on Windows should strongly consider WSL2 with Ubuntu. Inside WSL2, the Linux nvm installation works identically to native Linux, and the development experience is significantly more consistent with production server environments.

Understanding LTS vs. Current: Which Version to Install

Node.js follows a predictable release schedule that directly affects which version you should deploy.

Release TypeCadenceSupport DurationUse Case
**LTS (Long Term Support)**Even-numbered majors (18, 20, 22)30 months total (12 Active + 18 Maintenance)Production applications, enterprise workloads
**Current**Odd-numbered majors (19, 21, 23)6 months onlyFeature testing, library authors
**Maintenance LTS**Aging LTS releasesSecurity fixes onlyLegacy systems being migrated

Rule of thumb: Always deploy LTS on production. Use Current only in isolated development environments when you need to test compatibility with upcoming Node.js features.

Keeping Node.js Up to Date

Outdated Node.js versions expose your application to known V8 engine vulnerabilities, deprecated TLS configurations, and broken dependency compatibility. Treat Node.js upgrades as security maintenance, not optional improvements.

With nvm (all platforms):

nvm install --lts
nvm reinstall-packages <old-version>
nvm alias default node

The nvm reinstall-packages command migrates globally installed packages from the old version to the new one — a detail most guides omit that saves significant time.

With NodeSource on Debian/Ubuntu:

sudo apt-get update && sudo apt-get upgrade nodejs

With Homebrew on macOS:

brew update && brew upgrade node

With Chocolatey on Windows:

choco upgrade nodejs-lts

Managing Global npm Packages

Global npm packages install CLI tools accessible system-wide. Keep the global install list minimal — project-specific tools belong in devDependencies, not global installs, to ensure reproducible builds across environments.

Install a global package:

npm install -g yarn
npm install -g pm2
npm install -g typescript

List all globally installed packages:

npm list -g --depth=0

Remove a global package:

npm uninstall -g yarn

Common production-relevant global packages:

  • pm2 — Process manager for Node.js applications; handles clustering, auto-restart, and log management on Linux servers
  • typescript — TypeScript compiler (tsc)
  • nodemon — Development file watcher that auto-restarts the Node.js process on code changes
  • dotenv-cli — Loads .env files for environment-specific configuration

nvm and global packages: When you switch Node.js versions with nvm, global packages installed under the previous version are not automatically available. Either reinstall them or use nvm reinstall-packages <previous-version> to migrate them.

Post-Installation: Configuring npm for Production Environments

A clean Node.js installation requires a few additional configuration steps before it is production-ready.

Set npm registry (optional, for private registries or mirrors):

npm config set registry https://registry.npmjs.org/

Configure npm cache directory (relevant on servers with limited /tmp space):

npm config set cache /path/to/custom/cache

Disable package-lock.json generation (only if your team uses yarn.lock exclusively):

npm config set package-lock false

Set Node.js environment variable for production:

export NODE_ENV=production

Add this to /etc/environment or your application's systemd unit file on Linux servers to ensure Express.js, Next.js, and other frameworks activate their production optimizations.

If you are running Node.js applications on a Dedicated Server, configure pm2 as a systemd service to guarantee your application restarts after reboots:

pm2 start app.js --name "my-app"
pm2 startup systemd
pm2 save

Running Node.js Behind a Reverse Proxy

On production servers, Node.js applications should never be exposed directly on port 80 or 443. Use Nginx or Apache as a reverse proxy, and terminate TLS at the proxy layer. This is a critical architecture decision that the installation step directly enables.

A minimal Nginx configuration for a Node.js app running on port 3000:

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Pair this with a valid TLS certificate. SSL Certificates are essential for any Node.js application handling user data, authentication tokens, or API requests — not optional. Let's Encrypt via certbot is the standard free option; commercial certificates are appropriate for enterprise deployments.

Node.js on Shared Hosting vs. VPS

A question that comes up frequently: can Node.js run on shared hosting?

Standard Shared Web Hosting environments do not support Node.js in any meaningful way. Shared hosting is designed for PHP applications and does not provide shell access, persistent process management, or the ability to bind to custom ports — all of which Node.js requires.

For any real Node.js deployment, you need at minimum a VPS Hosting plan. A VPS gives you root access, a persistent process manager like pm2, and full control over the Node.js version and runtime configuration. If you need a managed control panel alongside your Node.js environment, a VPS with cPanel provides a middle ground between raw VPS access and managed hosting.

For compute-intensive Node.js workloads — machine learning inference, video transcoding, or large-scale data processing — a standard VPS may not be sufficient. GPU Hosting provides the hardware acceleration that CPU-bound Node.js processes cannot achieve on their own.

Technical Key-Takeaway Checklist

Use this as a pre-deployment verification checklist:

  • Version selection: Confirm you are running an active LTS release (node -v should return an even major number in active support window)
  • Installation method matches environment: nvm on developer machines; NodeSource or container on servers
  • npm version is current: Run npm install -g npm@latest after installing Node.js — the bundled npm is often not the latest
  • NODE_ENV is set: Verify echo $NODE_ENV returns production on all server environments
  • Process manager is configured: pm2 list shows your application running and pm2 startup has been executed
  • Reverse proxy is in place: Node.js is not directly exposed on port 80/443
  • TLS is terminated at the proxy: Valid certificate is installed and HTTPS redirects are enforced
  • Global package list is minimal: npm list -g --depth=0 shows only essential CLI tools
  • .nvmrc is committed to the repository: Ensures all team members and CI pipelines use the same Node.js version
  • Security updates are automated: A cron job or CI pipeline checks for new LTS patches monthly

FAQ

What is the difference between Node.js LTS and Current, and which should I install?

LTS (Long Term Support) releases are even-numbered majors (18, 20, 22) supported for 30 months with security and stability patches. Current releases are odd-numbered majors supported for only 6 months. Install LTS for any production or team development work. Use Current only for short-term feature experimentation.

Why does nvm show "command not found" after installation?

The nvm installer appends initialization code to your shell's RC file (~/.bashrc or ~/.zshrc), but the current terminal session has not reloaded it. Run source ~/.bashrc (or source ~/.zshrc for Zsh), or open a new terminal window. If the problem persists, manually verify that the nvm initialization block exists at the end of your RC file.

Can I run multiple Node.js versions simultaneously on the same server?

Yes, with nvm. Each version is installed in its own directory under ~/.nvm/versions/. You can switch the active version per shell session with nvm use <version>, or per project using a .nvmrc file. Different processes running different Node.js versions can coexist without conflict.

Why should I not install Node.js from the default Ubuntu/Debian apt repository?

The default Ubuntu and Debian repositories ship Node.js versions that are often two to four major versions behind the current LTS. For example, Ubuntu 22.04 ships Node.js 12 by default — a version that reached end-of-life in 2022. Always use the NodeSource repository or nvm to get a supported, current release.

How do I completely uninstall Node.js and start fresh?

The method depends on how it was installed. For NodeSource installs: sudo apt-get remove nodejs && sudo apt-get autoremove. For nvm: nvm uninstall <version> for specific versions, or delete the ~/.nvm directory entirely and remove the initialization lines from your RC file. For Homebrew: brew uninstall node. For the official installer on macOS/Windows, use the system's standard application uninstaller and manually remove any residual directories under /usr/local/lib/node_modules or %AppData%npm.

15%

Save 15% on All Hosting Services

Test your skills and get Discount on any hosting plan

Use code:

Skills
Get Started