本文目录导读:

Windows 系统
推荐工具:Chocolatey / Winget / Scoop
Chocolatey(最流行)
- 安装:以管理员身份打开 PowerShell,执行:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) - 安装软件(自动处理依赖):
choco install <包名> -y
- 示例:安装 7zip、VSCode、Node.js
choco install 7zip vscode nodejs -y
- 查看已安装:
choco list --local-only
Winget (Windows 11 内置)
- 搜索:
winget search <关键字> - 安装:
winget install <包名> - 示例:
winget install Microsoft.VisualStudioCode
Scoop(便携版,不污染系统路径)
- 安装:PowerShell 执行
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser irm get.scoop.sh | iex
- 安装软件:
scoop install <包名> - 依赖管理:Scoop 会自动下载并隔离依赖(如 Python 需要 OpenSSL)
macOS 系统
推荐工具:Homebrew
- 安装 Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 基础命令:
- 安装软件:
brew install <包名> - 安装带依赖的图形软件:
brew install --cask <包名> - 更新所有包:
brew update && brew upgrade
- 安装软件:
- 示例:安装 git、wget、python
brew install git wget python
- 查看依赖树:
brew deps --tree <包名>
Linux 发行版
Debian/Ubuntu(APT)
- 更新源:
sudo apt update - 安装软件及依赖:
sudo apt install <包名> - 自动处理依赖:
apt会自动安装所有必须的库(shared libraries) - 示例:
sudo apt install build-essential libssl-dev
Red Hat/CentOS/Fedora(DNF 或 YUM)
- 安装:
sudo dnf install <包名> - 查找依赖:
dnf deplist <包名>
Arch Linux(Pacman)
- 安装:
sudo pacman -S <包名> - 同步数据库:
sudo pacman -Syu
编程语言 / 开发环境依赖
Python (pip)
- 安装包:
pip install <包名> - 安装依赖文件:
pip install -r requirements.txt - 示例:安装 NumPy、Pandas
pip install numpy pandas
Node.js (npm 或 yarn)
- npm:
npm install <包名>或npm install(读取 package.json) - yarn:
yarn add <包名>或yarn install - 示例:
npm install express mongoose
Ruby (gem)
- 安装:
gem install <包名> - 使用 Bundler:
bundle install(读取 Gemfile)
Java (Maven 或 Gradle)
- Maven:在 pom.xml 声明依赖后运行
mvn install - Gradle:在 build.gradle 声明依赖后运行
gradle build
通用依赖管理原则
| 原则 | 说明 |
|---|---|
| 依赖隔离 | 使用虚拟环境(如 Python 的 venv、Node 的 node_modules)避免全局污染 |
| 锁定版本 | 记录依赖版本号(如 requirements.txt、package-lock.json)确保环境一致 |
| 更新依赖 | 定期运行更新命令(如 brew upgrade、apt upgrade)修复安全漏洞 |
| 卸载无用依赖 | 使用 autoremove(apt)或 choco uninstall 清理残留 |
图形化工具(适合初学者)
- Windows:使用 Chocolatey GUI(
choco install chocolateygui) - macOS:使用 Homebrew GUI(如 Cakebrew)
- Linux:使用 Synaptic Package Manager(
sudo apt install synaptic)
依赖冲突与解决
依赖冲突常见于 Python / Node 项目,使用以下方法排查:
- 显示依赖树:
pip show <包名>/npm ls - 指定版本:
pip install package==1.2.3/npm install package@1.2.3 - 重建环境:删除
node_modules或__pycache__后重新安装
| 场景 | 推荐包管理器 | 安装命令举例 |
|---|---|---|
| Windows 全局软件 | Chocolatey | choco install vscode |
| macOS 全局软件 | Homebrew | brew install wget |
| Linux 系统软件 | APT / DNF | sudo apt install curl |
| Python 项目 | pip | pip install flask |
| Node 项目 | npm | npm install express |
如果你能提供更具体的操作系统或编程语言环境,我可以给出更精确的依赖管理方案。
标签: 包管理器
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。