Modern concrete building with abstract cutouts and amp

Photo by Declan Sun on Unsplash

💻 Tech & Devices15 min read📊 Easy

How to Install npm: A Simple Step-by-Step Guide

Learn how to install npm quickly and easily on Windows, macOS, and Linux by installing Node.js. Get started with package management for JavaScript development.

Quick Summary

Installing npm (Node Package Manager) is typically done by installing Node.js, as npm comes bundled with it. This guide will walk you through the process, ensuring you have the essential tools for JavaScript development. By following these steps, you'll be ready to manage packages for your Node.js projects.

Jump to steps ↓

Advertisement

🛒 What You Need

  • A computer (Windows, macOS, or Linux)
  • Internet connection
  • Administrator privileges on your system
  • A web browser
  • Command-line interface (Terminal/Command Prompt)

📋 Steps

1

Check for Existing Node.js and npm Installation

Before proceeding, it's wise to check if Node.js and npm are already installed on your system. Open your terminal or command prompt and type node -v and then npm -v. If version numbers are displayed for both, you already have them installed. If you receive an error message or no output, you'll need to proceed with the installation.

2

Download the Node.js Installer

Visit the official Node.js website at nodejs.org. Look for the recommended "LTS" (Long Term Support) version, which is stable and widely used. Download the installer package specifically for your operating system (e.g., .msi for Windows, .pkg for macOS, or source for Linux).

3

Run the Node.js Installer

Locate the downloaded installer file and double-click to run it. Follow the on-screen prompts of the setup wizard. Generally, accepting the default installation options is sufficient, as these include Node.js runtime, npm, and other essential tools. Ensure you agree to the license agreement to continue.

Advertisement

4

Verify Node.js and npm Installation

After the installation process completes, open a new terminal or command prompt window. It's crucial to open a new window to ensure the system's PATH variable is updated. Type node -v and npm -v again. You should now see the version numbers, confirming that both Node.js and npm have been successfully installed.

5

Update npm to the Latest Version (Optional)

Although npm is installed with Node.js, it's often a good practice to update npm to its latest stable version. This ensures you have access to the newest features, performance improvements, and bug fixes. In your terminal, run the command: npm install -g npm@latest. This command globally updates your npm client. For more detailed guidance, refer to How to Install npm: A Comprehensive Guide for Developers.

6

Test npm by Installing a Package

To confirm that npm is fully functional and ready for use, you can try installing a simple package globally. For example, run npm install -g cowsay in your terminal. If the package installs without any errors and you can then run cowsay Hello, your npm setup is complete and ready for managing dependencies in your projects.

💡 Tips & Tricks

  • Always use the LTS (Long Term Support) version of Node.js for development and production environments, as it offers maximum stability and regular updates.
  • Familiarize yourself with essential npm commands like npm init to start a new project, npm install to add dependencies, and npm run