-
-
Notifications
You must be signed in to change notification settings - Fork 168
Node.js Installation Guide
This guide covers how to install Node.js 20 (or greater) on macOS, Windows, and Linux. We'll focus on using NVM (Node Version Manager) which allows you to easily manage multiple Node.js versions.
- Why Use NVM?
- Prerequisites
- macOS Installation
- Windows Installation
- Linux Installation
- Installing Node.js with NVM
- Setting Up the Next.js App
- Verifying Installation
- Managing Multiple Node Versions
NVM (Node Version Manager) is highly recommended because it:
- β Allows you to install and switch between multiple Node.js versions
- β Avoids permission issues with global npm packages
- β Makes it easy to match the exact Node version required by different projects
- β Simplifies Node.js upgrades and downgrades
- β Keeps your system clean and organized
Required Node.js Version: Node.js 20 or greater
You can verify this requirement in the project's package.json:
{
"engines": {
"node": ">=20.0.0"
}
}-
Install NVM using the install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bashOr using wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install. sh | bash -
Add NVM to your shell profile:
For Zsh (default on macOS Catalina and later):
# Add to ~/. zshrc export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
For Bash:
# Add to ~/.bash_profile or ~/.bashrc export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
-
Reload your shell configuration:
source ~/.zshrc # or source ~/.bash_profile
-
Verify NVM installation:
nvm --version
While you can install Node.js directly with Homebrew, using NVM is preferred for version management:
# Direct installation (not recommended if you want version management)
brew install node@20Windows uses a different tool called nvm-windows (not the same as the macOS/Linux version).
-
Download nvm-windows:
- Visit nvm-windows releases page
- Download the latest
nvm-setup.exe
-
Run the installer:
- Double-click
nvm-setup.exe - Follow the installation wizard
- Choose installation directory (default is fine)
- Choose the symlink path for Node.js
- Double-click
-
Verify installation: Open Command Prompt or PowerShell and run:
nvm version
If you're using WSL, follow the Linux installation instructions below.
-
Install NVM using the install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bashOr using wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash -
Add NVM to your shell profile:
# The installer usually adds this automatically to ~/.bashrc or ~/.zshrc export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
-
Reload your shell configuration:
source ~/.bashrc # or source ~/.zshrc
-
Verify NVM installation:
nvm --version
Once NVM is installed, follow these steps on any platform:
# Install Node.js version 20 (latest v20.x)
nvm install 20
# Or install the latest LTS (Long Term Support) version
nvm install --lts
# Or install a specific version
nvm install 20.11.0# Use Node.js 20
nvm use 20
# Set Node.js 20 as the default version
nvm alias default 20# Check Node.js version
node -v
# Should output: v20.x.x (or higher)
# Check npm version
npm -v
# Should output: 10.x.x (or higher)Now that Node.js 20+ is installed, you can set up the Next.js application:
# If using git
git clone <repository-url>
cd <project-directory>
# Or if you downloaded a ZIP, extract and navigate to the foldernpm installThis will install all required packages from package.json.
npm run devThe Next.js app should now be running at http://localhost:3000
# Create an optimized production build
npm run build
# Start the production server
npm startnode -v # Should show v20.x.x or higher
npm -v # Should show npm version# In your project directory
npm run devVisit http://localhost:3000 in your browser.
# List installed Node versions
nvm ls
# List all available Node versions (macOS/Linux)
nvm ls-remote
# List all available Node versions (Windows)
nvm list available# Switch to Node. js 20
nvm use 20
# Switch to Node.js 18
nvm use 18
# Switch to latest LTS
nvm use --lts# Uninstall Node.js 18
nvm uninstall 18Create a .nvmrc file in your project root to specify the required Node version:
echo "20" > .nvmrcThen anyone can automatically use the correct version:
nvm use
# Automatically uses the version specified in .nvmrcmacOS/Linux:
- Ensure NVM is added to your shell profile (
.zshrc,.bashrc,.bash_profile) - Restart your terminal or run
source ~/.zshrc
Windows:
- Restart Command Prompt or PowerShell with Administrator privileges
- Ensure nvm-windows installed correctly
# Make sure you've activated a Node version
nvm use 20
# Set a default version
nvm alias default 20NVM automatically handles permissions, but if you encounter issues:
# Never use sudo with npm when using NVM
# Instead, reinstall the package without sudo
npm install <package-name>-
Check Node version:
node -v # Must be 20 or higher -
Clear npm cache and reinstall:
npm cache clean --force rm -rf node_modules package-lock.json npm install
-
Check for port conflicts:
# If port 3000 is in use, specify a different port npm run dev -- -p 3001
- NVM for macOS/Linux (GitHub)
- nvm-windows (GitHub)
- Node.js Official Website
- Next.js Documentation
- npm Documentation
# Install Node.js 20
nvm install 20
# Use Node.js 20
nvm use 20
# Set default version
nvm alias default 20
# Verify installation
node -v && npm -v
# Install project dependencies
npm install
# Run development server
npm run dev
# Build for production
npm run build && npm start- β Install NVM (Node Version Manager)
- β Install Node.js 20 or greater using NVM
- β Navigate to your Next.js project directory
- β
Run
npm installto install dependencies - β
Run
npm run devto start the development server - β Open http://localhost:3000 in your browser
You're now ready to develop and run the Next.js application! π