linux/软件管理.md
2025-03-19 15:52:20 +08:00

191 lines
3.7 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h2><center>软件管理</center></h2>
------
## 一YUM 包管理工具
YUM 是基于 RPM 的前端工具,支持自动解决依赖关系。
### 1. 基本操作
安装软件包:
```bash
yum install package_name
# 例:安装 httpd
yum install httpd
# 重新安装
yum reinstall package_name
```
更新软件包:
```bash
yum update package_name
# 更新所有软件包
yum update
```
卸载软件包:
```bash
yum remove package_name
# 例:卸载 httpd
yum remove httpd
```
搜索软件包:
```bash
yum search keyword
# 例:搜索与 PHP 相关的包
yum search php
# 查询命令提供者
yum provides package_name
# 查询yum源
yum repolist
```
查看软件信息:
```bash
yum info package_name
```
列出已安装的软件:
```bash
yum list installed
```
### 2. 管理软件仓库Repositories
启用/禁用仓库:
- 修改仓库配置文件(位于 `/etc/yum.repos.d/`),设置 `enabled=1`(启用)或 `enabled=0`(禁用)。
- 临时禁用仓库:
```bash
yum --disablerepo=repo_name install package_name
```
### 3. 清理缓存
```bash
yum clean all # 清理所有缓存
yum makecache # 重建缓存
```
## 二RPM 包管理工具
RPM 直接操作 `.rpm` 文件,适合本地软件包管理。
### 1. 安装本地 RPM 包
```bash
rpm -ivh package.rpm
```
### 2. 升级 RPM 包
```bash
rpm -Uvh package.rpm
```
### 3. 卸载 RPM 包
```bash
rpm -e package_name
```
### 4. 查询已安装的包
```bash
rpm -qa | grep keyword
```
### 5. 查看包依赖
```bash
yum deplist package_name
```
## 三:编译安装工具
### 1. 安装编译工具和依赖
编译前需安装开发工具链和依赖库:
```bash
[root@wxin ~]# yum groupinstall "Development Tools" # 安装编译工具gcc/make等
[root@wxin ~]# yum install -y epel-release # 启用EPEL仓库
[root@wxin ~]# yum install -y pkgconfig openssl-devel zlib-devel libxml2-devel # 示例:安装常见依赖
```
### 2. 下载源码包
通过 `wget` 或浏览器下载源码包(通常为 `.tar.gz` 或 `.tar.xz`
```bash
[root@wxin ~]# wget https://example.com/software-1.0.0.tar.gz
```
### 3. 解压源码包
```bash
[root@wxin ~]# tar -zxvf software-1.0.0.tar.gz # 解压 .tar.gz
[root@wxin ~]# cd software-1.0.0 # 进入源码目录
```
### 4. 配置编译选项
使用 `./configure` 检查系统环境并生成 Makefile
```bash
[root@wxin ~]# ./configure \
--prefix=/usr/local/software \ # 指定安装目录(默认是 /usr/local
--enable-feature \ # 启用特定功能
--disable-deprecated # 禁用不推荐的功能
```
**常见问题处理:**
如果报错 `configure: error: missing XXX library`
```bash
[root@wxin ~]# yum search XXX # 查找缺失的依赖包
[root@wxin ~]# yum install XXX-devel # 安装开发包(注意安装 -devel 后缀的包)
```
### 5. 编译源码
```bash
[root@wxin ~]# make -j $(nproc) # 使用多核CPU加速编译例如4核CPU用 -j4
```
### 6. 安装软件
```bash
[root@wxin ~]# make install # 将编译好的文件安装到 --prefix 指定目录
```
### 7. 配置环境变量(可选)
如果安装到自定义目录(如 `/usr/local/software/bin`),需添加 PATH
```bash
[root@wxin ~]# echo 'export PATH=/usr/local/software/bin:$PATH' >> ~/.bashrc
[root@wxin ~]# source ~/.bashrc
```
### 8. 验证安装
```bash
[root@wxin ~]# software --version # 检查是否输出正确版本
```