Node.js Installation and Initial Setup
Node.js is a runtime environment that lets you run JavaScript outside the browser, such as on servers or in the terminal. It is used for front-end development, back-end development, CLI tools, and AI-integrated applications.
This page explains how to install Node.js with nvm and create your first project.
Prerequisites
- You know the basics of terminal commands. See Terminal Basics.
- Homebrew is installed. See Homebrew Installation.
- nvm is installed. See Installing nvm.
Why Install Node.js Through nvm?
You can install Node.js directly with the official installer or Homebrew, but using nvm has several advantages:
- Multiple versions can coexist - You can use different Node.js versions per project.
- You do not need sudo - Permission errors are less likely, and global package management is safer.
- Version switching is easy - Switch with a single
nvm use <version>command.
Installation Steps
Step 1: Confirm Homebrew is installed
Check that Homebrew is installed.
brew --version
# Example: Homebrew 4.x.xIf it is not installed, finish Homebrew Installation first.
Step 2: Confirm nvm is installed
Check that nvm is installed.
command -v nvm
# If "nvm" is shown, you are goodIf it is not installed, finish Installing nvm first.
Step 3: Install Node.js
Install Node.js with nvm.
nvm install --lts # Install the latest LTS release
node -v # Check version, for example v22.x.x
npm -v # Check npm version, for example 10.x.xThe LTS (Long Term Support) release is stable and supported for a long time. I recommend LTS for new projects.
Step 4: Update npm to the latest version (optional)
Update npm, which is installed with Node.js, to the latest version.
npm install -g npm
npm -v # Check the version after the updateStep 5: Create your first project
After installation, create a simple project to confirm that everything works.
mkdir my-first-project # Create a project folder
cd my-first-project # Move into the folder
npm init -y # Generate package.json automaticallyRunning npm init -y creates a package.json file. This file is used to manage project information and dependencies.
ls # Confirm that package.json was createdAfter Installation
Run the following commands to confirm that everything is installed correctly:
node -v # Example: v22.x.x
npm -v # Example: 10.x.x
nvm current # Current Node.js version in useCommon Problems and Fixes
Q: node: command not found appears
A: nvm may not be configured correctly. Run source ~/.zshrc for Zsh or source ~/.bashrc for Bash to reload the shell. If that does not help, review the steps in Installing nvm.
Q: EACCES: permission denied appears during npm install
A: This means the global npm install location is not writable. If you installed Node.js through nvm, this should not happen. To avoid using sudo, standardize on nvm-based installation.
Q: package.json not found
A: You are running the command in a folder that does not contain package.json. Run npm init -y first, or cd into the project folder and try again.
Summary
- Install Node.js through nvm
- Use
nvm install --ltsto install the latest LTS release (v22 series in 2026) - Use
npm init -yto create the projectpackage.json - Use
node -vandnpm -vto confirm the installation
Reference
See the references for the external specifications and background sources used on this page.[1][2]
References
- Node.js, Introduction to Node.js
- MDN Web Docs, Learn web development