LIVEReading: Foundation #03Topic: What is npm (and pip)?Read time: 6 minSection: PACKAGE LIVEReading: Foundation #03Topic: What is npm (and pip)?Read time: 6 minSection: PACKAGE
CBW
// FOUNDATION#03Beginner

What is npm (and pip)?

Why every install command starts with the same three letters. The world's most boring infrastructure, explained.

Read time5 min
LevelBeginner
Need beforeTerminal #01
UnlocksMost install commands
AudienceFirst-timers
// THE SHORT ANSWER

npm and pip are app stores for code libraries.

When a guide says <code>npm install whisper</code> or <code>pip install openai</code>, it's doing the same thing as "Get" on the App Store — downloading a piece of code someone else wrote so you don't have to. npm is for JavaScript projects. pip is for Python. That's the whole difference.

The first time I followed an AI guide, the second line was pip install openai. I typed it. It worked. I had no idea what had just happened. I assumed "pip" was some kind of magic.

It's not magic. It's a package manager — a command-line app store. The same mental model you use for the App Store or the Play Store applies here: someone built a thing, uploaded it to a central library, and now you can install it with one command. No downloading .dmg files. No dragging to Applications. Just one line.

There are two you'll see constantly on this site: npm (for JavaScript/Node.js projects) and pip (for Python projects). This article explains both in about five minutes. After this, every install command will make sense immediately.

// 01What a package manager actually does

A package is a bundle of code someone else wrote and published. A package manager is the tool that downloads and installs those bundles for you. It also keeps track of which ones you have, so you can remove or update them later.

// what you already know
App Store
// this is the same thing
npm / pip
You search for "Spotify."
You type <code>npm install openai</code>.
You tap Get / Install.
You press Enter.
The App Store downloads it.
npm downloads it from the registry.
It appears on your home screen.
It appears in your project folder.
Updates happen automatically.
You run <code>npm update</code> when needed.

The difference is that package managers work for code libraries — pieces of code that other programs use internally — rather than apps you open with a click. You install a library once, and then any code in your project can use it.

// 02npm vs pip — how to know which one to use

The rule is simple: follow the language. If the guide you're following is a Python project, you'll use pip. If it's a JavaScript/Node.js project, you'll use npm. The guide will make it obvious — the install command in the README tells you which one.

npm — for JavaScript / Node.js

npm stands for Node Package Manager. It ships with Node.js, so if you install Node.js you automatically have npm too. Almost all web-based AI tools, Next.js apps, and browser-extension projects use npm.

Terminal · npm examples
# install one package
$npm install openai
added 23 packages in 2s
# install everything a project needs
$npm install
added 847 packages in 14s
# run a script defined in package.json
$npm run dev
▲ Next.js 14.0.0
- Local: http://localhost:3000

pip — for Python

pip is Python's package manager. It comes bundled with Python 3. Most AI/ML tools — Whisper, LangChain, Stable Diffusion, PyTorch — are Python packages installed with pip.

Terminal · pip examples
# install one package
$pip install openai
Successfully installed openai-1.3.5
# install everything a project needs
$pip install -r requirements.txt
Successfully installed whisper-1.1.10 torch-2.1.0 ...

// 03The two files that describe what's installed

Every project that uses packages has one of these files. They're not code — they're manifests: lists of which packages the project needs and at what version. When someone else clones your project, they run one command and the manifest tells their package manager exactly what to install.

package.json (npm projects)

This file lives in the root of every npm project. When you see a repo with a package.json, you know: run npm install and you'll have everything. You rarely edit this by hand — npm install <package-name> adds the entry automatically.

// package.json (simplified)
{
  "name": "my-ai-project",
  "dependencies": {
    "openai": "^1.3.5",
    "next": "^14.0.0"
  }
}

requirements.txt (pip projects)

Same idea for Python. One package per line, optional version pinned. Run pip install -r requirements.txt and the whole project installs. Most AI tool repos include this file.

// requirements.txt
openai>=1.3.0
whisper==1.1.10
torch>=2.0.0
numpy

// 04How to read an install command

Every install command follows the same pattern. Once you see it, you can read any guide's install section without needing to think.

// anatomy of an install command
npm   install   openai   @1.3.5
 ↑       ↑        ↑        ↑
tool  action  package  version (optional)

pip   install   openai==1.3.5
 ↑       ↑        ↑
tool  action  package + version

The version is optional. Without it, you get the latest stable version, which is almost always what you want. Guides only pin a version when a newer one breaks something — they'll tell you why.

  • npm install <package> — installs into the current project folder
  • npm install -g <package> — installs globally (available everywhere, not just this project). Rare — only when a guide says -g.
  • pip install <package> — installs into the current Python environment
  • pip install --upgrade <package> — upgrades an existing package

// 05Now you. Run your first install command.

Five minutes. We'll check if npm and pip are already on your machine (they probably are), then install one real package each. No project needed — we're just practicing the motion.

// TRY IT — 5 minutes

Check your package managers and run one install

  1. Open a terminal. (You did this in Foundation #01. Same window.)
  2. Check if npm is installed: type npm --version and press Enter. You should see a version number like 10.2.3. If you get "command not found," install Node.js from nodejs.org — npm comes with it.
  3. Check if pip is installed: type pip --version (or pip3 --version) and press Enter. You should see something like pip 23.3 from /usr/local/lib/python3.11. If missing, install Python from python.org.
  4. Install a real package with pip: type pip install httpx and press Enter. httpx is a tiny, harmless HTTP library — good practice without side effects.
  5. Verify it installed: type pip show httpx. You'll see the version, location, and description. That's it — you just installed a package.
Done. You now know how to install any package any guide asks you to. The only variable is the package name.
// READ NEXT3
ALL 5 →