Programming Language Oriented Package Managers
Programming languages have their own ecosystems for distributing libraries and tools. Language-specific package managers handle dependencies at the application level, often coexisting with system-level package managers.
pip (Python)
pip is the package installer for Python. It installs packages from PyPI (Python Package Index).
Basic usage:
pip install requests # Install a package pip install -r requirements.txt # Install from requirements file pip uninstall requests # Remove a package pip list # List installed packages pip freeze > requirements.txt # Export installed versions
Virtual environments isolate project dependencies:
python -m venv .venv # Create virtual environment source .venv/bin/activate # Activate (Linux/macOS) .venv\Scripts\activate # Activate (Windows) pip install -r requirements.txt deactivate # Deactivate
npm (Node.js)
npm manages JavaScript packages for Node.js. It installs packages locally in node_modules/ or globally.
npm install lodash # Install locally npm install -g typescript # Install globally npm uninstall lodash # Remove package npm update # Update packages npm list # Show dependency tree npm audit # Security audit
pnpm and yarn are popular alternatives to npm.
cargo (Rust)
Cargo is Rust's build system and package manager. It fetches dependencies from crates.io and compiles projects.
cargo new myproject # Create new project cd myproject cargo add serde # Add dependency cargo build # Build project cargo run # Build and run cargo test # Run tests cargo publish # Publish to crates.io
go (Go)
Go uses modules for dependency management, handled by the go command.
go mod init myproject # Initialise module go get github.com/gin-gonic/gin # Add dependency go build # Build binary go run main.go # Build and run go test ./... # Run tests
Go modules are stored in go.mod and go.sum files.
gem (Ruby)
RubyGems manages Ruby libraries (gems).
gem install rails # Install a gem gem uninstall rails # Remove a gem gem list # List installed gems gem update # Update gems bundle init # Initialise Bundler bundle add rails # Add dependency to Gemfile
composer (PHP)
Composer manages PHP dependencies, similar to npm for Node.js.
composer init # Initialise project composer require symfony/console # Add dependency composer update # Update dependencies composer install # Install from lock file composer dump-autoload # Regenerate autoloader
Best Practices
- Lock files: Always commit lock files (
package-lock.json,Cargo.lock,go.sum) for reproducible builds. - Version pinning: Specify exact versions in production to avoid unexpected changes.
- Virtual environments: Use language-specific virtual environments to isolate dependencies.
- Private registries: Use private registries for internal packages to avoid leaking code.