Ensiklopedia VibeKoding: An Introduction to Package Managers.Ensiklopedia VibeKoding: An Introduction to Package Managers.
> ๐ก Learning Guide: You don't have to reinvent the wheel when writing code โ 99% of the functionality you need has already been written and published online by someone else. A package manager is the tool that helps you find, download, and manage these "ready-made parts." This chapter revolves around one core question: how to make code dependencies reproducible, collaborative, and maintainable?> ๐ก Learning Guide: You don't have to reinvent the wheel when writing code โ 99% of the functionality you need has already been written and published online by someone else. A package manager is the tool that helps you find, download, and manage these "ready-made parts." This chapter revolves around one core question: how to make code dependencies reproducible, collaborative, and maintainable?
Different programming languages and operating systems have their own ecosystem toolchains, but the underlying logic is exactly the same.Different programming languages and operating systems have their own ecosystem toolchains, but the underlying logic is exactly the same.
๐ Try it out: Select an ecosystem you're familiar with and explore its mainstream package management tools.๐ Try it out: Select an ecosystem you're familiar with and explore its mainstream package management tools.
Every ecosystem has a central repository behind it that stores all downloadable packages:Every ecosystem has a central repository behind it that stores all downloadable packages:
| Ecosystem | Registry | Package Count |
|---|---|---|
| JavaScript | [npmjs.com](https://npmjs.com) | 2 million+ |
| Python | [pypi.org](https://pypi.org) | 500K+ |
| Rust | [crates.io](https://crates.io) | 150K+ |
| Go | [pkg.go.dev](https://pkg.go.dev) | 500K+ |
| macOS/Linux Tools | [formulae.brew.sh](https://formulae.brew.sh) | 7,000+ |
| Windows Software | [winget.run](https://winget.run) / [chocolatey.org](https://chocolatey.org) | Tens of thousands |
Similar functionality, with differences mainly in speed and disk usage:Similar functionality, with differences mainly in speed and disk usage:
text Disk usage: pnpm (hard link sharing) < yarn PnP (zero node_modules) < npm (full copy) Install speed: pnpm โ yarn > npm Usage: npm (most universal) > pnpm (recommended for new projects) > yarn (some teams)
Recommendation: Use pnpm for new projects, stick with the existing tool for existing projects, and don't switch casually.Recommendation: Use pnpm for new projects, stick with the existing tool for existing projects, and don't switch casually.
| winget | Chocolatey | Scoop | |
|---|---|---|---|
| Official backing | Microsoft official | Third-party | Third-party |
| Requires admin | Partially needed | Yes | Not needed |
| Best for | Daily software installation | Enterprise batch deployment | Dev tool management |
| Package count | Many, growing fast | Most (10,000+) | Focused on dev tools |
Recommendation: Use winget for daily use, scoop for dev tools, Chocolatey for enterprise automation.Recommendation: Use winget for daily use, scoop for dev tools, Chocolatey for enterprise automation.
------
After typing npm install axios, the command line goes quiet for a few seconds, and then it's done. What exactly happened during those seconds?After typing npm install axios, the command line goes quiet for a few seconds, and then it's done. What exactly happened during those seconds?
๐ Try it out: Select a package, click "Run," and observe the full installation process.๐ Try it out: Select a package, click "Run," and observe the full installation process.
โ Dependency Resolutionโ Dependency Resolution
The package manager first "understands" what you want to install. Take axios as an example โ it itself depends on packages like follow-redirects, form-data, etc., which also need to be installed. This process is called building the dependency tree.The package manager first "understands" what you want to install. Take axios as an example โ it itself depends on packages like follow-redirects, form-data, etc., which also need to be installed. This process is called building the dependency tree.
โก Fetchโก Fetch
Download all needed packages from the Registry (compressed .tgz archives). Smart package managers will:Download all needed packages from the Registry (compressed .tgz archives). Smart package managers will:
โข Linkโข Link
Extract the downloaded packages into the node_modules/ directory and set up the reference relationships.Extract the downloaded packages into the node_modules/ directory and set up the reference relationships.
โฃ Write Lockfileโฃ Write Lockfile
Write the exact version numbers from this installation into package-lock.json (or yarn.lock / pnpm-lock.yaml).Write the exact version numbers from this installation into package-lock.json (or yarn.lock / pnpm-lock.yaml).
bash # โโ JavaScript (npm) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ npm install # Install all dependencies per package.json npm install axios # Install a new package (production dependency) npm install -D jest # Install a dev dependency (only used during development) npm install -g tsx # Global install (available in any directory) npm uninstall axios # Uninstall a package npm update # Upgrade all packages to latest compatible versions npm run build # Run scripts defined in package.json npx create-react-app . # Run temporarily without installing to project # โโ Python (pip) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ pip install requests # Install a package pip install requests==2.28.0 # Install a specific version pip freeze > requirements.txt # Export current dependency list pip install -r requirements.txt # Install from a list # โโ Rust (cargo) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ cargo add serde # Add a dependency (auto-updates Cargo.toml) cargo build # Build the project cargo test # Run tests cargo run # Run the project # โโ Go (go mod) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ go get github.com/gin-gonic/gin # Add a dependency go mod tidy # Clean up dependencies (remove extras, add missing) go build ./... # Build # โโ Windows (winget) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ winget install Git.Git # Install software winget upgrade --all # Update all installed software
The scripts field in package.json is npm's built-in task runner:The scripts field in package.json is npm's built-in task runner:
json { "scripts": { "dev": "vite", "build": "vite build", "test": "jest", "lint": "eslint src/" } }
Running: npm run dev, npm run build. Benefits:Running: npm run dev, npm run build. Benefits:
node_modules/.bin to PATH, so locally installed tools are directly usableAuto environment setup: Running automatically adds node_modules/.bin to PATH, so locally installed tools are directly usable------
This is one of the most confusing concepts for beginners.This is one of the most confusing concepts for beginners.
bash npm install axios # Local install: into ./node_modules/, only available in current project npm install -g typescript # Global install: into system directory, available in any project/directory
| Local Install | Global Install | |
|---|---|---|
| Location | ./node_modules/ | System-level directory (e.g., /usr/local/lib/) |
| Best for | Project dependency libraries (axios, vue, react) | CLI tools (tsc, eslint, create-react-app) |
| Version isolation | Each project has independent versions โ | One version shared across the machine โ ๏ธ |
| Team consistency | Lockfile ensures consistency โ | Different people may have different versions โ ๏ธ |
> Library dependencies (axios, lodash, vue) should always be installed locally;> Library dependencies (axios, lodash, vue) should always be installed locally;
> CLI tools (tsc, eslint) should preferably be installed locally too, invoked with npx.> CLI tools (tsc, eslint) should preferably be installed locally too, invoked with npx.
Why are CLI tools also recommended for local installation?Why are CLI tools also recommended for local installation?
Suppose you globally installed eslint@8, but Project A needs the new rules from eslint@9 โ you'd have to switch back and forth between global and project versions. Install eslint locally and invoke it with npx eslint ., so each project can independently configure its own version.Suppose you globally installed eslint@8, but Project A needs the new rules from eslint@9 โ you'd have to switch back and forth between global and project versions. Install eslint locally and invoke it with npx eslint ., so each project can independently configure its own version.
npx is npm's built-in package runner that lets you run a package without installing it:npx is npm's built-in package runner that lets you run a package without installing it:
bash # Run create-vue without installing it, to initialize a project npx create-vue my-project # Run prettier without installing it, to format files npx prettier --write src/ # Force a specific version (ignoring any installed version) npx typescript@5.4 tsc --version
Python's uvx and Rust's cargo run also provide similar "run temporarily" capabilities:Python's uvx and Rust's cargo run also provide similar "run temporarily" capabilities:
bash uvx ruff check . # Python: temporarily run the ruff checker cargo install ripgrep # Rust: install globally, becomes system command rg
------
In package.json, you'll see entries like:In package.json, you'll see entries like:
json { "dependencies": { "axios": "^1.6.8", "typescript": "~5.4.0" } }
What do ^ and ~ mean here?What do ^ and ~ mean here?
๐ Try it out: Hover over the parts of a version number to understand their meaning; click range operators to see which versions are accepted.๐ Try it out: Hover over the parts of a version number to understand their meaning; click range operators to see which versions are accepted.
| Approach | Pros | Cons |
|---|---|---|
"axios": "1.6.8" (exact pin) | Fully predictable | Security patches can't auto-update |
"axios": "^1.6.8" (compatible range, recommended) | Auto-get bug fixes and new features | Rarely may introduce minor incompatibilities |
"axios": "*" (any version) | Always latest | Major version upgrades can completely break code |
Best practice: Declare ranges with ^ + pin actual versions with a lockfile โ use both together.Best practice: Declare ranges with ^ + pin actual versions with a lockfile โ use both together.
When you depend on 50 packages, and each of those depends on several more, the "dependency tree" can have hundreds of nodes. If two of your dependencies need incompatible versions of the same library, you have a "dependency conflict."When you depend on 50 packages, and each of those depends on several more, the "dependency tree" can have hundreds of nodes. If two of your dependencies need incompatible versions of the same library, you have a "dependency conflict."
How different ecosystems solve this:How different ecosystems solve this:
------
Suppose package.json says "axios": "^1.6.0":Suppose package.json says "axios": "^1.6.0":
1.6.8You install today โ gets 1.6.81.7.0 (released last night)Your teammate installs tomorrow โ might get 1.7.0 (released last night)1.7.1CI server next week โ might get 1.7.1Same code, three different results. A lockfile records the exact version of every package, so everyone installs identically.Same code, three different results. A lockfile records the exact version of every package, so everyone installs identically.
| Scenario | Command | Behavior |
|---|---|---|
| Dev environment sync | npm install | References lockfile, doesn't upgrade versions |
| CI / production deploy | npm ci | Strictly follows lockfile; errors if there's a discrepancy |
| Active version upgrade | npm update | Upgrades within allowed range, updates lockfile |
Applications must commit; libraries published to npm may not.Applications must commit; libraries published to npm may not.
requirements.txt itself acts as a lockfile and should be committedโ
Python projects: requirements.txt itself acts as a lockfile and should be committedgo.sum must be committed for integrity verificationโ
Go projects: go.sum must be committed for integrity verification------
Python has a concept that requires special attention: virtual environments (venv).Python has a concept that requires special attention: virtual environments (venv).
Why are they needed?Why are they needed?
Python installs packages globally by default. Your Project A needs requests==2.28, and Project B needs requests==2.31 โ they'll conflict.Python installs packages globally by default. Your Project A needs requests==2.28, and Project B needs requests==2.31 โ they'll conflict.
Solution: Create an independent virtual environment for each project so they don't interfere with each other.Solution: Create an independent virtual environment for each project so they don't interfere with each other.
bash # 1. Create a virtual environment (run in project root directory) python -m venv .venv # 2. Activate the virtual environment source .venv/bin/activate # macOS / Linux .venv\Scripts\activate # Windows (Command Prompt CMD) .venv\Scripts\Activate.ps1 # Windows (PowerShell) # 3. After activation, pip install only affects the current virtual environment, not the global one pip install requests # 4. Exit the virtual environment deactivate
> โ ๏ธ Common Windows issue: PowerShell blocks script execution by default. First run:> โ ๏ธ Common Windows issue: PowerShell blocks script execution by default. First run:
> ```powershell> ```powershell
> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
> ```> ```
Modern alternatives:Modern alternatives:
conda create -n myproject python=3.11 โ even manages the Python version itselfconda create -n myproject python=3.11 โ even manages the Python version itselfuv venv && source .venv/bin/activate โ written in Rust, creates blazingly fastuv venv && source .venv/bin/activate โ written in Rust, creates blazingly fastShould .venv be committed to Git?Should .venv be committed to Git?
No! .venv is generated locally and should be added to .gitignore. Use requirements.txt or pyproject.toml to describe dependencies.No! .venv is generated locally and should be added to .gitignore. Use requirements.txt or pyproject.toml to describe dependencies.
------
Q: Should node_modules be committed to Git?Q: Should node_modules be committed to Git?
No! It's typically hundreds of MB and should be added to .gitignore. With package-lock.json, anyone can quickly rebuild it with npm install.No! It's typically hundreds of MB and should be added to .gitignore. With package-lock.json, anyone can quickly rebuild it with npm install.
Q: Installation fails / getting weird errors?Q: Installation fails / getting weird errors?
bash # Clear cache, delete old installation, start fresh npm cache clean --force rm -rf node_modules package-lock.json # macOS/Linux rmdir /s /q node_modules && del package-lock.json # Windows CMD npm install
Q: Installation is too slow?Q: Installation is too slow?
bash # Switch to a domestic mirror (recommended to write to .npmrc file, don't pollute global config) echo "registry=https://registry.npmmirror.com" > .npmrc # pip can also configure mirrors pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple
Q: How to handle package security vulnerabilities?Q: How to handle package security vulnerabilities?
bash npm audit # Scan for known vulnerabilities npm audit fix # Auto-fix compatible vulnerabilities npm audit fix --force # Force upgrade (may be breaking, use with caution)
Q: How to tell if a package is trustworthy?Q: How to tell if a package is trustworthy?
Check on [npmjs.com](https://npmjs.com) or [bundlephobia.com](https://bundlephobia.com):Check on [npmjs.com](https://npmjs.com) or [bundlephobia.com](https://bundlephobia.com):
Q: Where does winget install software on Windows?Q: Where does winget install software on Windows?
winget installs to system directories (requires admin) or %LOCALAPPDATA%\Microsoft\WindowsApps by default. Scoop installs all software uniformly in %USERPROFILE%\scoop\apps\, making it easy to manage and migrate.winget installs to system directories (requires admin) or %LOCALAPPDATA%\Microsoft\WindowsApps by default. Scoop installs all software uniformly in %USERPROFILE%\scoop\apps\, making it easy to manage and migrate.
------
| English Term | Chinese Translation | Explanation |
|---|---|---|
| Package | ๅ / ๅบ | Code modules written and published by others |
| Registry | ๆณจๅ่กจ / ไปๅบ | The central storage server for all packages (e.g., npmjs.com) |
| Dependency | ไพ่ต | Other packages your project needs to run |
| devDependency | ๅผๅไพ่ต | Packages only needed during development (test frameworks, build tools, etc.) |
| Lockfile | ้ๆไปถ | Records exact version numbers, ensuring environment consistency |
| SemVer | ่ฏญไนๅ็ๆฌ | MAJOR.MINOR.PATCH version naming convention |
| node_modules | ๆจกๅ็ฎๅฝ | The directory where npm-installed packages are actually stored |
| venv | ่ๆ็ฏๅข | An isolated sandbox for Python project packages |
| tarball | ๅ็ผฉๅ | The distribution format of packages, usually .tgz files |
| Hoisting | ๆๅ | npm lifts sub-dependencies to the top level to avoid duplicate installations |
| Phantom Dependency | ๅนฝ็ตไพ่ต | Packages that can be used without being declared in config (pnpm prevents this) |
| npx | โ | npm's built-in package runner, runs packages temporarily without installing |
| go.sum | โ | Go module hash verification file, prevents dependency tampering |
| Crate | โ | The unit name for "packages" in the Rust ecosystem |
| winget | โ | Windows' official package manager (built into Windows 10/11) |
------
Remember the core with these four points:Remember the core with these four points:
^ safely gets updates; when MAJOR changes, be careful.Semantic versioning = communication language: ^ safely gets updates; when MAJOR changes, be careful.npx / uvx for temporary tool runs to keep your environment clean.Local > Global: Install project dependencies locally whenever possible; use npx / uvx for temporary tool runs to keep your environment clean.