Installing Node.js and npm
Before you can use npm, you need to install Node.js. npm comes bundled with Node.js, so you'll get both with a single installation.
Installation Methods
There are several ways to install Node.js:
Method 1: Official Installer (Recommended for Beginners)
- Visit nodejs.org
- Download the LTS (Long Term Support) version
- Run the installer and follow the prompts
- Restart your terminal
Method 2: Node Version Manager (Recommended for Developers)
Using a version manager like nvm (Node Version Manager) lets you easily switch between Node.js versions.
On macOS/Linux:
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Install latest LTS version
nvm install --lts
# Use the installed version
nvm use --lts
On Windows:
Use nvm-windows:
# After installing nvm-windows
nvm install lts
nvm use lts
Method 3: Package Managers
macOS (Homebrew):
brew install node
Ubuntu/Debian:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
Windows (Chocolatey):
choco install nodejs-lts
Verifying Your Installation
After installation, open a new terminal window and run:
node --version
# Should output something like: v20.10.0
npm --version
# Should output something like: 10.2.3
If both commands show version numbers, you're ready to go!
Understanding the Versions
| Component | Current LTS | Purpose |
|---|---|---|
| Node.js | v20.x or v22.x | JavaScript runtime |
| npm | v10.x | Package manager |
LTS vs Current:
- LTS (Long Term Support): Stable, recommended for most users
- Current: Latest features, may be less stable
Common Installation Issues
"command not found: npm"
This usually means:
- Node.js isn't installed properly
- The installation path isn't in your system PATH
- You need to restart your terminal
Fix: Close and reopen your terminal, or restart your computer.
Permission Errors on macOS/Linux
If you see EACCES permission errors:
# Fix npm permissions (recommended)
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
# Add to your ~/.bashrc or ~/.zshrc:
export PATH=~/.npm-global/bin:$PATH
Multiple Node Versions Conflict
If you have multiple installations:
# Check which node is being used
which node
# Check all installed versions (if using nvm)
nvm list
Your First npm Command
Let's verify npm works by checking the registry:
npm ping
# Should output: Ping success: {...}
You can also see all available npm commands:
npm help
Practice: Version Check
The commands below show how to check your Node.js and npm versions:
npm Configuration
npm stores its configuration in several places:
# View all npm config settings
npm config list
# View a specific setting
npm config get registry
# Set a configuration value
npm config set init-author-name "Your Name"
Common configuration options:
| Setting | Description | Default |
|---|---|---|
registry | Package registry URL | https://registry.npmjs.org/ |
prefix | Global package install location | System-dependent |
cache | Package cache location | ~/.npm |
Key Takeaways
- Download from nodejs.org for the simplest installation
- Use nvm if you need multiple Node.js versions
- Verify installation with
node --versionandnpm --version - LTS versions are recommended for stability
- Fix permission issues by configuring npm's prefix
What's Next?
Now that you have npm installed, let's dive into the most important file in any npm project: package.json.

