Installing Node.js
Getting Node.js on your machine takes about two minutes. Here is how.
Try it Yourself →Option 1: Official Website
Go to nodejs.org and download the LTS (Long Term Support) version. The LTS version is stable and recommended for most developers. Run the installer and follow the prompts.
Option 2: Package Managers
macOS: brew install node
Ubuntu: sudo apt install nodejs npm
Windows: choco install nodejs
Option 3: NVM (Recommended)
NVM (Node Version Manager) lets you install and switch between Node.js versions:
# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Install latest LTS
nvm install --lts
# Use it
nvm use --lts
NVM is useful because different projects might need different Node.js versions. With NVM, you can switch instantly.
Verify Your Installation
node --version # v20.11.0 or similar
npm --version # 10.2.4 or similar
If you see version numbers, you are ready.
Your First Script
Create a file called hello.js and type this:
console.log("Hello from Node.js!");
Run it:
node hello.js
You should see Hello from Node.js! printed to your terminal. Congratulations — you just ran JavaScript outside the browser.