💻 Programming

Package Manager

Package Manager

A tool for installing libraries and managing dependencies. npm, pip, cargo, and go mod are representative examples.

📖 Detailed Explanation

A package manager is a tool that automates the installation, updating, removal, and dependency management of software libraries. It saves developers the effort of downloading libraries and configuring paths themselves, and it also resolves version conflicts. It is an essential tool in modern software development.

Each language has its representative package managers. JavaScript uses npm, yarn, and pnpm; Python uses pip, conda, and poetry; Rust uses cargo; and Go uses go mod. Each package manager fetches packages from a central repository (registry).

Dependency management is a core function of a package manager. Files such as package.json, requirements.txt, and Cargo.toml specify the packages and versions a project needs. Lock files (package-lock.json, Cargo.lock, etc.) record exact versions to ensure reproducible builds.

Understanding semantic versioning (SemVer) helps you manage dependencies better. In the MAJOR.MINOR.PATCH format, ^1.2.3 means the 1.x.x range, and ~1.2.3 means the 1.2.x range. Specifying version ranges appropriately lets you automatically receive security patches while maintaining compatibility.

💻 Code Example

# npm (JavaScript)
npm init -y                    # 프로젝트 초기화
npm install express            # 패키지 설치
npm install -D typescript      # 개발 의존성 설치
npm update                     # 패키지 업데이트
npm audit                      # 보안 취약점 검사

# pip (Python)
pip install requests           # 패키지 설치
pip install -r requirements.txt # 파일에서 설치
pip freeze > requirements.txt  # 의존성 내보내기
pip install --upgrade pip      # pip 자체 업그레이드

# cargo (Rust)
cargo new myproject            # 프로젝트 생성
cargo add serde                # 패키지 추가
cargo build                    # 빌드
cargo update                   # 의존성 업데이트

# go mod (Go)
go mod init myproject          # 모듈 초기화
go get github.com/gin-gonic/gin # 패키지 추가
go mod tidy                    # 미사용 의존성 정리

# pnpm (npm 대안, 효율적인 디스크 사용)
pnpm install                   # node_modules 설치
pnpm add lodash                # 패키지 추가

🗣️ Examples of Practical Conversations

Senior: The node_modules folder is so large that our CI builds are slow. What if we switched to pnpm?

Junior: How is pnpm different from npm?

Senior: It shares packages via symbolic links, so disk usage is much lower. Installation is fast too. You can keep using your existing package.json as is, so migration is easy as well.

Interviewer: What is the role of package-lock.json?

Candidate: It records the exact versions of the dependency tree. If you specify ^1.0.0 in package.json, the version can vary within the 1.x.x range, but with a lock file, the same version is installed in every environment. It is essential for reproducible builds.

Interviewer: What is the difference between devDependencies and dependencies?

Candidate: dependencies are the packages needed in production, while devDependencies are things like testing tools and linters needed only during development. npm install --production excludes devDependencies.

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

Reviewer: This package version is set to * instead of ^, which is risky.

Author: I was trying to always use the latest version.

Reviewer: A major version change may include breaking changes. If you specify ^, you only receive patch and minor updates, which is safe.

⚠️ Cautions

🔗 Related Terms

📚 Learn More