π’ Node.js & npm Installation Guide
π¦ What Are Node.js and npm?
- Node.js is a JavaScript runtime that allows you to run JavaScript outside the browserβprimarily used to build server-side applications.
- npm (Node Package Manager) is a tool that comes with Node.js and is used to install and manage packages (libraries and tools) for your project.
π macOS Installation
β
1. Using Homebrew (Recommended)
Make sure Homebrew is installed first.
π₯ Install Node.js + npm
β
Verify Installation
node -v # Should return a version like v20.x.x
npm -v # Should return a version like 10.x.x
πͺ Windows Installation
β
1. Download the Installer
- Visit the official Node.js site: https://nodejs.org
- Click on the LTS version (recommended for most users).
- Run the downloaded installer and follow the instructions (you can leave all options as default).
β
2. Verify Installation
Open Command Prompt (cmd
) and run:
π§ Linux Installation (Ubuntu/Debian)
β
1. Update Your System
β
2. Install Node.js and npm
sudo apt install nodejs npm
This installs both node
and npm
, but it might be an older version.
π§ Optional: Install the Latest Version with NodeSource
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
β
3. Verify Installation
π§ͺ Test Installation
Create a simple JavaScript file:
echo "console.log('Node is working!');" > test.js
node test.js
Expected output:
π οΈ Updating npm
To update npm
to the latest version:
π§° Tips
- Use
nvm
(Node Version Manager) if you want to install and switch between multiple Node versions. View nvm guide.
- Always install Node.js via official channels or a trusted version manager.