Installing Node.js
This guide explains how to install Node.js on Windows, macOS, and Linux. Node.js is a core dependency for HagiCode-related local tooling such as OpenSpec, frontend tooling, and several developer CLIs.
Installing Node.js
Section titled “Installing Node.js”Method One: Official Installer (Recommended)
Section titled “Method One: Official Installer (Recommended)”- Visit the Node.js Official Website
- Download the LTS (Long Term Support) version Windows installer (
.msifile) - Double-click to run the installer
- Follow the installation wizard prompts to complete installation:
- Accept the license agreement
- Choose installation path (default is fine)
- Make sure “Automatically install the necessary tools” is checked
- Click “Install” to start installation
- After installation completes, click “Finish”
Method Two: Using winget
Section titled “Method Two: Using winget”Open PowerShell or Command Prompt and run:
winget install OpenJS.NodeJS.LTSAfter installation, reopen the terminal for changes to take effect.
Method One: Official Installer (Recommended)
Section titled “Method One: Official Installer (Recommended)”- Visit the Node.js Official Website
- Download the LTS (Long Term Support) version macOS installer (
.pkgfile) - Double-click to run the installer
- Follow the installation wizard prompts to complete installation:
- Click “Continue”
- Accept the license agreement
- Choose installation disk
- Click “Install” and enter administrator password
- After installation completes, click “Close”
Method Two: Using Homebrew
Section titled “Method Two: Using Homebrew”If you have Homebrew installed, you can install Node.js via terminal:
brew install nodeUsing NodeSource Repository (Recommended)
Section titled “Using NodeSource Repository (Recommended)”This is the best way to get the latest Node.js version:
# Use curl to download the installation scriptcurl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -sudo apt-get install -y nodejsUsing apt Package Manager
Section titled “Using apt Package Manager”If you don’t need the latest version, you can use the default Ubuntu repository:
sudo apt-get updatesudo apt-get install -y nodejs npmUsing NodeSource Repository (Recommended)
Section titled “Using NodeSource Repository (Recommended)”# Use curl to download the installation scriptcurl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -sudo yum install -y nodejsUsing yum Package Manager
Section titled “Using yum Package Manager”sudo yum install -y nodejs npmUsing dnf Package Manager
Section titled “Using dnf Package Manager”sudo dnf install -y nodejs npmUsing Version Management Tools
Section titled “Using Version Management Tools”If you need to switch between multiple Node.js versions, you can use version management tools.
nvm (Node Version Manager)
Section titled “nvm (Node Version Manager)”Linux/macOS
Section titled “Linux/macOS”# Install using curlcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Or install using wgetwget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bashAfter installation, reload your shell configuration:
source ~/.bashrc# Or for Zsh userssource ~/.zshrcWindows
Section titled “Windows”On Windows, we recommend using nvm-windows:
- Download the latest
nvm-setup.exefrom nvm-windows releases - Run the installer
- Reopen Command Prompt or PowerShell
After installing nvm, you can use it to install and manage Node.js versions:
# Install the latest LTS version (recommended)nvm install --lts
# Install Node.js 24 (recommended version)nvm install 24
# Install a specific Node.js versionnvm install 18.20.0
# List installed versionsnvm list
# Switch to a specified Node.js versionnvm use 24
# Set default versionnvm alias default 24
# Windows nvm-windows syntax is slightly differentnvm install 24nvm use 24fnm (Fast Node Manager)
Section titled “fnm (Fast Node Manager)”fnm is a faster and simpler Node.js version management tool built with Rust.
Linux/macOS
Section titled “Linux/macOS”# Install using curlcurl -fsSL https://fnm.vercel.app/install | bash
# After installation, reload shell configurationsource ~/.bashrc# Or for Zsh userssource ~/.zshrcWindows
Section titled “Windows”# Use scoopscoop install fnm
# Or use wingetwinget install Schniz.fnm# Install the latest LTS version (recommended)fnm install --lts
# Install Node.js 24 (recommended version)fnm install 24
# Install a specific Node.js versionfnm install 18.20.0
# List installed versionsfnm list
# Switch to a specified Node.js versionfnm use 24
# Set default versionfnm default 24Acceleration for Mainland China Users
Section titled “Acceleration for Mainland China Users”If you are in Mainland China, downloading Node.js and npm packages may be slow. Here are some acceleration solutions.
Using Domestic Mirror Sources
Section titled “Using Domestic Mirror Sources”npm Taobao Mirror (Recommended)
Section titled “npm Taobao Mirror (Recommended)”# Temporarily use Taobao mirrornpm install --registry=https://registry.npmmirror.com
# Permanently set Taobao mirrornpm config set registry https://registry.npmmirror.com
# Verify mirror is set successfullynpm config get registryUsing nrm to Manage Mirror Sources
Section titled “Using nrm to Manage Mirror Sources”nrm (npm registry manager) helps you quickly switch npm mirror sources:
# Install nrmnpm install -g nrm
# List available mirror sourcesnrm ls
# Switch to Taobao mirrornrm use taobao
# Test mirror source speednrm testAccelerating Node.js Installer Downloads
Section titled “Accelerating Node.js Installer Downloads”Taobao provides mirror downloads for Node.js installers:
- Download Address: https://npmmirror.com/mirrors/node/
Visit the above address and select the version you need to download.
If downloading nvm or other tools from GitHub is slow, you can use the FastGit mirror:
# Use FastGit to accelerate nvm installationcurl -o- https://fastgit.org/nvm-sh/nvm/raw/master/install.sh | bashDomestic Homebrew Mirrors
Section titled “Domestic Homebrew Mirrors”If you use Homebrew in Mainland China, you can configure domestic mirrors for acceleration:
# Install Homebrew using domestic mirror/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
# Or use USTC mirrorexport HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottlesMainland China Specific Package Managers
Section titled “Mainland China Specific Package Managers”cnpm is an npm client provided by the Taobao team that uses the Taobao mirror by default:
# Install cnpmnpm install -g cnpm --registry=https://registry.npmmirror.com
# Use cnpm to install packagescnpm install <package-name>Verifying Mirror Acceleration Effect
Section titled “Verifying Mirror Acceleration Effect”After setting up mirrors, verify by:
# Test download speedtime npm install express --registry=https://registry.npmmirror.com
# Compare with official source speedtime npm install express --registry=https://registry.npmjs.orgVerifying Installation
Section titled “Verifying Installation”After installation, verify that Node.js and npm are installed correctly:
# Check Node.js versionnode --version
# Check npm versionnpm --versionSample Verification Output
Section titled “Sample Verification Output”Successful verification output should look like:
$ node --versionv24.3.0
$ npm --version10.2.3Troubleshooting
Section titled “Troubleshooting”Windows Issues
Section titled “Windows Issues”If node or npm commands are not available after installation:
- Restart Command Prompt or PowerShell
- If still not available, manually add Node.js to PATH:
- Search for “Environment Variables” and open “Edit system environment variables”
- Click “Environment Variables”
- Find “Path” in “System variables” and click “Edit”
- Add Node.js installation path (default:
C:\Program Files\nodejs\) - Click “OK” to save changes
If you encounter execution policy errors when using nvm:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUsermacOS Issues
Section titled “macOS Issues”If you encounter permission errors when installing global npm packages:
# Fix npm permissionssudo chown -R $(whoami) ~/.npmsudo chown -R $(whoami) /usr/local/lib/node_modulesIf commands are not available after installation, restart the terminal or manually add to PATH (usually in /usr/local/bin).
Linux Issues
Section titled “Linux Issues”If you encounter permission errors when installing global npm packages, it is recommended to use Node.js version management tools (like nvm or fnm) instead of system package managers.
If the Node.js version installed via system package manager is too old:
- Use NodeSource repository (recommended, see above)
- Or use version management tools (nvm/fnm)
Checking Environment
Section titled “Checking Environment”If verification fails, check the following:
# Check if Node.js is in PATHwhere node
# Check installation pathGet-Command node# Check if Node.js is in PATHwhich node
# Check installation pathls -l $(which node)# Check if Node.js is in PATHwhich node
# Check installation pathls -l $(which node)
# Check version detailsnode -vNext Steps
Section titled “Next Steps”After Node.js installation is complete, you can continue with the following steps:
Need More Help?
Section titled “Need More Help?”If you encounter issues not covered here:
- Visit the Node.js Official Documentation
- Review the HagiCode Product Overview for current product and tooling context
- Visit the HagiCode website for the latest support entry points