What Node.js is and why you need it installed
Node.js is a runtime environment that lets you run JavaScript code outside of a web browser — on your computer, a server, or in the cloud. If you're building web applications, command-line tools, or anything that needs JavaScript to run on its own, you need Node.js installed first.
Installation is straightforward on any operating system. You download an installer or use your system's package manager, run it, and Node.js is ready to use. The whole process takes about five minutes. After installation, you'll have access to the npm (Node Package Manager) command-line tool, which lets you download and manage code libraries that other developers have written.
Key Takeaways
- Download Node.js from nodejs.org — choose the LTS (Long Term Support) version unless you need the latest features.
- On Windows and Mac, run the installer file and follow the on-screen prompts; on Linux, use your package manager (apt, yum, or brew depending on your distribution).
- After installation, open a terminal or command prompt and type node --version to confirm Node.js is working.
- npm installs automatically with Node.js, so you can start downloading packages and running JavaScript files right away.
- If installation fails, the most common cause is a previous incomplete installation — uninstall Node.js completely before trying again.
Installing Node.js on Windows
Go to nodejs.org and click the button labeled "LTS" (Long Term Support). This downloads the stable version that most developers use. Save the .msi file to your computer, then double-click it to open the installer.
The installer walks you through a series of screens. Click "Next" on each one until you reach the "Tools for Native Modules" screen — you can leave this unchecked unless you know you need it. Continue clicking "Next" and then "Install" at the final screen. Windows may ask for permission to make changes to your computer; click "Yes". The installer finishes in about a minute.
Once the installer closes, open Command Prompt (search for "cmd" in the Windows search bar) and type this command:
node --version
If you see a version number like "v18.17.0", Node.js is installed correctly. If you see "command not found" or similar, restart your computer and try again — Windows sometimes needs a restart to recognize the new program.
Installing Node.js on Mac
Go to nodejs.org and click the button labeled "LTS". This downloads a .pkg file. Double-click the file to open the installer.
The installer shows you a series of screens. Click "Continue" on each one, then click "Agree" when asked to accept the license. On the "Installation Type" screen, click "Install" — you do not need to change any settings. The installer asks for your Mac password; type it in and click "Install Software". The process takes about a minute.
Once the installer closes, open Terminal (search for "Terminal" in Spotlight by pressing Command + Space, then type "Terminal" and press Enter). Type this command:
node --version
If you see a version number, Node.js is installed. If you see "command not found", close Terminal completely, wait a few seconds, open it again, and try the command once more.
Installing Node.js on Linux
The method depends on which Linux distribution you're using. Open a terminal and run the appropriate command for your system.
On Ubuntu or Debian: Type this command and press Enter:
sudo apt update && sudo apt install nodejs npm
Your system will ask for your password. Type it in (you won't see the characters as you type) and press Enter. The system downloads and installs Node.js and npm automatically.
On Fedora, CentOS, or RHEL: Type this command:
sudo dnf install nodejs npm
On Arch Linux: Type this command:
sudo pacman -S nodejs npm
After the installation finishes, open a new terminal window and type:
node --version
If you see a version number, the installation worked.
Verifying npm is installed and working
Node.js and npm install together, so if Node.js works, npm should too. To confirm, open your terminal or command prompt and type:
npm --version
You should see a version number like "9.6.7". This means npm is ready to use. You can now download packages by typing commands like npm install package-name in your terminal.
If npm doesn't work but Node.js does, try restarting your computer. If that doesn't fix it, uninstall Node.js completely and reinstall it using the steps above.
Troubleshooting a failed installation
The most common reason Node.js won't install is that a previous version is partially installed on your system. Uninstall Node.js completely before trying again.
On Windows: Open Control Panel, click "Programs", then "Programs and Features". Find "Node.js" in the list, click it, and click "Uninstall". Follow the prompts to remove it completely. Then download and install the latest version from nodejs.org.
On Mac: Open Finder, go to Applications, find Node.js (if it appears there), and drag it to Trash. Then download and install the latest version from nodejs.org. If you installed using Homebrew, type brew uninstall node in Terminal instead.
On Linux: Type sudo apt remove nodejs npm (Ubuntu/Debian), sudo dnf remove nodejs npm (Fedora), or sudo pacman -R nodejs npm (Arch). Then reinstall using the commands in the Linux section above.
If Node.js still won't install after a complete uninstall, check that you have enough disk space (at least 500 MB free) and that your user account has permission to install software. On Windows, try running the installer as Administrator by right-clicking it and selecting "Run as Administrator".
What to do after installation
Once Node.js is installed and working, you can start writing and running JavaScript files. Create a file called test.js with this code inside:
console.log("Node.js is working");
Save the file, open your terminal or command prompt, navigate to the folder where you saved it, and type:
node test.js
If you see the message "Node.js is working" printed in your terminal, everything is set up correctly. You're now ready to start building projects, downloading packages with npm, and running JavaScript outside the browser.
Frequently Asked Questions
Should I install the LTS version or the latest version?
Install LTS (Long Term Support) unless you have a specific reason not to. LTS versions are stable, receive security updates for years, and work with almost all packages. The latest version has newer features but can break compatibility with some older packages.
Do I need to install npm separately?
No. npm installs automatically when you install Node.js. You do not need to download or install it separately. Once Node.js is installed, you can use npm right away.
What if I see "permission denied" when trying to use npm?
On Mac or Linux, you may need to use sudo before npm commands, like sudo npm install package-name. If this happens repeatedly, your npm permissions may need adjustment — search for "fix npm permissions" for your specific operating system.
Can I have multiple versions of Node.js installed at the same time?
Yes, but it requires a version manager like nvm (Node Version Manager) on Mac or Linux, or nvm-windows on Windows. This is useful if different projects need different Node.js versions. For most beginners, one version is enough.
Why does my terminal say "command not found" after installation?
Your terminal hasn't recognized the new program yet. Close the terminal completely, wait a few seconds, and open a new terminal window. If that doesn't work, restart your computer. Windows and Mac sometimes need a restart to register new programs.