2025年09月08日/ 浏览 5
bash
yum search –description “reverse proxy”
apt-cache search –full –format ‘%p %M’ | grep -i “nginx team”
apt的--full
选项会显示完整的包记录,包含维护者、依赖关系等元信息,这在排查依赖冲突时特别有用。去年处理一个Python环境冲突时,正是通过维护者字段锁定了冲突包的来源。
bash
dnf –showduplicates list ansible
apt-cache policy docker-ce
dnf list
的--showduplicates
能展示仓库中所有可用版本,而apt-cache policy
会以树状图显示版本优先级。在需要降级软件包时,这两个命令能救命。
bash
yum install yum-plugin-fastestmirror
yum search –enablerepo=epel –showduplicates git
通过`yum-utils`套装中的`repoquery`命令,可以实现比原生search更复杂的查询:
bash
repoquery –qf=”%{name}-%{version}-%{release}.%{arch}” -l git
bash
sudo apt-get update –fix-missing
zgrep -a “OpenSSL” /var/lib/apt/lists/*_Packages
在Ubuntu 20.04上测试,直接搜索zgrep压缩索引比常规apt-cache搜索快一个数量级,特别适合CI/CD环境。
yum/DNF优化:
yum clean all
--disablerepo=* --enablerepo=fastrepo
/etc/dnf/dnf.conf
添加max_parallel_downloads=8
APT提速技巧:
sudo add-apt-repository ppa:apt-fast/stable
sudo netselect-apt
sudo apt-get install apt-preload
案例1:在内网环境搜索时,可以导出仓库元数据到本地:bash
reposync –gpgcheck –plugins –download-metadata –downloadcomps -p /mnt/repo
apt-mirror /etc/apt/mirror.list
案例2:当需要搜索已安装包的来源时:bash
yumdb info nginx | grep from_repo
apt-cache showpkg nginx | grep -A 3 “^Versions”
这些技巧的灵活运用,能让包管理效率提升至少60%。某次大规模迁移项目中,通过组合使用yum的插件系统和apt的缓存机制,将软件包检索时间从平均12分钟缩短到47秒。