Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Packages and Services

Linux pip and npm basics

Reference for the essential pip and npm commands on Linux: install, uninstall, list, freeze, virtual environments, global installs and avoiding common mistakes.

pip installs Python packages from PyPI; npm installs JavaScript packages from the npm registry. They are not part of the Linux package system: they manage libraries for one language, usually inside a project folder, and they never talk to apt or dnf. Knowing a handful of commands covers most daily use.

The most important habit is isolation. Install project libraries into a virtual environment (Python) or into the project's node_modules (Node) instead of the whole system, so that projects with different needs cannot break each other or the operating system's own tools.

Terminal
python3 -m venv .venv && . .venv/bin/activate
pip install requests
npm install express

Try it

The sandbox has no network, so nothing can be downloaded. The first example creates a virtual environment (an offline operation, here without pip because the sandbox lacks ensurepip) and shows how it changes PATH; the second parses a sample requirements.txt and package.json.

Bash A virtual environment (offline)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Dependency files (sample data)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
pip [--user] COMMAND [OPTIONS] [PACKAGES]
npm COMMAND [OPTIONS] [PACKAGES]
pip npm Description
pip install pkg npm install pkg Install a package (npm also adds it to package.json).
pip install -r requirements.txt npm install (or npm ci) Install everything a project lists.
pip uninstall pkg npm uninstall pkg Remove a package.
pip list npm ls Show what is installed.
pip freeze > requirements.txt package-lock.json Record exact versions.
pip show pkg npm view pkg Show package details.
pip install -U pkg npm update pkg Upgrade a package.
python3 -m venv .venv n/a Create an isolated environment.
pip install -e . npm link Install a project in editable (development) mode.
pipx install tool npm install -g tool Install a command-line tool.

Version specifiers: pkg==1.2.3 is exact, pkg>=1.2 is a minimum in pip. In npm, ^1.2.3 allows minor and patch updates, ~1.2.3 allows patch updates only.

Returns: 0 on success, non-zero on resolution failures, missing packages or network errors.

Usage notes

  • Never sudo pip install. It can overwrite files managed by the distribution and break system tools. Recent Debian, Ubuntu and Fedora releases refuse system-wide installs with an "externally managed environment" error; use a venv, or pipx for command-line tools.
  • Use python3 -m pip so you are sure the pip matches the python3 you run. Inside an activated venv plain pip is correct.
  • Global npm installs need root unless you set a prefix (npm config set prefix ~/.local). Prefer project-local installs and run tools with npx tool.
  • Commit lock files. package-lock.json pins every dependency; npm ci installs exactly that and fails if it does not match package.json. For pip, tools such as pip-tools or uv produce lock files.
  • node_modules and .venv are build artifacts: keep them out of Git (.gitignore) and recreate them from the dependency file.
  • Security: installing a package can run code (setup.py, npm postinstall scripts). Install only packages you trust, and audit with npm audit or pip-audit.
  • Offline or CI use: pip download and npm ci --prefer-offline work with caches; set --index-url or a registry mirror in restricted networks.
  • Compared with apt: language managers give newer versions and per-project control, but no system-level security updates; apt packages are older but maintained by the distribution.