Linux 基础 - 软件安装
Linux 软件安装
源码包编译安装
几乎所有开源程序使用的都是 C 语言,所以就用 C 语言演示源码编译安装
现有这样一个文件,现在要安装这个程序
[root@localhost home]# cat hello.c
#include <stdio.h>
int main() {
printf("Hello World!\n\n");
return 0;
}
只需要制作 Makefile
[root@localhost home]# ll
总用量 8
-rw-r--r--. 1 root root 82 9月 28 15:06 hello.c
-rw-r--r--. 1 root root 72 9月 28 15:21 Makefile
[root@localhost home]# cat Makefile
hello:hello.o
gcc -o hello hello.c
install:
cp hello /usr/local/bin/
现在这就是一个安装程序了,只需要两条命令就可以安装成功
[root@localhost home]# make
cc -c -o hello.o hello.c
gcc -o hello hello.c
[root@localhost home]# make install
cp hello /usr/local/bin/
[root@localhost home]# hello
Hello World!
实际上,有很多开源软件本身是不包含 Makefile 的,而是需要用户根据具体的需求使用软件包目录中的 configure 工具。生成适合用户特定需求的 Makefile,最典型的源码编译安装软件的过程包括 3 个步骤
- 第一步,运行 configure 命令,结合必要参数生成 Makefile
- 第二步,运行 make 命令生成各类模块和主程序
- 第三步,运行 make install 命令将必要的文件复制到安装目录
RPM 安装软件
[root@localhost ~]# rpm --help
用法: rpm [选项...]
查询/验证软件包选项:
-a, --all 查询/验证所有软件包
-f, --file 查询/验证文件属于的软件包
-g, --group 查询/验证组中的软件包
-p, --package 查询/验证一个软件包
--pkgid query/verify package(s) with package identifier
--hdrid query/verify package(s) with header identifier
--triggeredby query the package(s) triggered by the package
--whatrequires query/verify the package(s) which require a dependency
--whatprovides 查询/验证提供相关依赖的软件包
--nomanifest 不把非软件包文件作为清单处理
查询选项(用 -q 或 --query):
-c, --configfiles 列出所有配置文件
-d, --docfiles 列出所有程序文档
-L, --licensefiles list all license files
--dump 转储基本文件信息
-l, --list 列出软件包中的文件
--queryformat=QUERYFORMAT 使用这种格式打印信息
-s, --state 显示列出文件的状态
验证选项(用 -V 或 --verify):
--nofiledigest 不验证文件摘要
--nofiles 不验证软件包中文件
--nodeps 不验证包依赖
--noscript 不执行验证脚本
安装/升级/擦除选项:
--allfiles 安装全部文件,包含配置文件,否则配置文件会被跳过。
--allmatches 移除所有符合 <package> 的软件包(如果 <package> 被指定未多个软件包,常常会导致错误出现)
--badreloc 对不可重定位的软件包重新分配文件位置
-e, --erase=<package>+ 清除 (卸载) 软件包
--excludedocs 不安装程序文档
--excludepath=<path> 略过以 <path> 开头的文件
--force --replacepkgs --replacefiles 的缩写
-F, --freshen=<packagefile>+ 如果软件包已经安装,升级软件包
-h, --hash 软件包安装的时候列出哈希标记 (和 -v 一起使用效果更好)
--ignorearch 不验证软件包架构
--ignoreos 不验证软件包操作系统
--ignoresize 在安装前不检查磁盘空间
-i, --install 安装软件包
--justdb 更新数据库,但不修改文件系统
--nodeps 不验证软件包依赖
--nofiledigest 不验证文件摘要
--nocontexts 不安装文件的安全上下文
--noorder 不对软件包安装重新排序以满足依赖关系
--noscripts 不执行软件包脚本
--notriggers 不执行本软件包触发的任何脚本
--nocollections 请不要执行任何动作集
--oldpackage 更新到软件包的旧版本(带 --force 自动完成这一功能)
--percent 安装软件包时打印百分比
--prefix=<dir> 如果可重定位,便把软件包重定位到 <dir>
--relocate=<old>=<new> 将文件从 <old> 重定位到 <new>
--replacefiles 忽略软件包之间的冲突的文件
--replacepkgs 如果软件包已经有了,重新安装软件包
--test 不真正安装,只是判断下是否能安装
-U, --upgrade=<packagefile>+ 升级软件包
--reinstall=<packagefile>+ reinstall package(s)
所有 rpm 模式和可执行文件的通用选项:
-D, --define=“MACRO EXPR” 定义值为 EXPR 的 MACRO
--undefine=MACRO undefine MACRO
-E, --eval=“EXPR” 打印 EXPR 的宏展开
--macros=<FILE:…> 从文件 <FILE:...> 读取宏,不使用默认文件
--noplugins don't enable any plugins
--nodigest 不校验软件包的摘要
--nosignature 不验证软件包签名
--rcfile=<FILE:…> 从文件 <FILE:...> 读取宏,不使用默认文件
-r, --root=ROOT 使用 ROOT 作为顶级目录 (default: "/")
--dbpath=DIRECTORY 使用 DIRECTORY 目录中的数据库
--querytags 显示已知的查询标签
--showrc 显示最终的 rpmrc 和宏配置
--quiet 提供更少的详细信息输出
-v, --verbose 提供更多的详细信息输出
--version 打印使用的 rpm 版本号
Options implemented via popt alias/exec:
--scripts list install/erase scriptlets from package(s)
--setperms set permissions of files in a package
--setugids set user/group ownership of files in a package
--setcaps set capabilities of files in a package
--restore restore file/directory permissions
--conflicts list capabilities this package conflicts with
--obsoletes list other packages removed by installing this package
--provides list capabilities that this package provides
--requires list capabilities required by package(s)
--info list descriptive information from package(s)
--changelog list change logs for this package
--xml list metadata in xml
--triggers list trigger scriptlets from package(s)
--last list package(s) by install time, most recent first
--dupes list duplicated packages
--filesbypkg list all files from each package
--fileclass list file names with classes
--filecolor list file names with colors
--fscontext list file names with security context from file system
--fileprovide list file names with provides
--filerequire list file names with requires
--filecaps list file names with POSIX1.e capabilities
Help options:
-?, --help Show this help message
--usage Display brief usage message
[root@localhost home]#
安装软件包
# 安装软件包
[root@localhost ~]# rpm -ivh NAME-VERSION.rpm
# 测试安装软件包,不做真实安装
[root@localhost ~]# rpm -ivh -test NAME-VERSION.rpm
# 安装软件包,并重新定义安装路径
[root@localhost ~]# rpm -ivh --relocate /=/usr/local/NAME-VERSION.rpm
# 强行安装软件包,忽略依赖关系
[root@localhost ~]# rpm -ivh NAME-VERSION.rpm --force --nodeps
# 升级软件包
[root@localhost ~]# rpm -Uvh NAME-VERSION.rpm
# 强行升级软件包,忽略依赖关系
[root@localhost ~]# rpm -Uvh NAME-VERSION.rpm --force --nodeps
# 删除软件包,并忽略依赖关系
[root@localhost ~]# rpm -e NAME.rpm --nodeps
# 导入签名
[root@localhost ~]# rpm --import RPM-GPG-KEY
# 查询某个包是否已经安装
[root@localhost ~]# rpm -q NAME
# 查询系统中所有已安装的包
[root@localhost ~]# rpm -qa
# 查询某个文件属于哪个包
[root@localhost ~]# rpm -qf /etc/auto.misc
# 查询某个已安装软件所包含的所有文件
[root@localhost ~]# rpm -ql NAME
# 查询某个包的依赖关系
[root@localhost ~]# rpm -qpR NAME-VERSION.rpm
# 查询某个包的信息
[root@localhost ~]# rpm -qpi NAME-VERSION.rpm
# 删除软件包
[root@localhost ~]# rpm -e NAME
yum 安装软件
yum 在文章中多次使用过
# 安装软件包
[root@localhost ~]# yum install NAME
# 安装软件组
[root@localhost ~]# yum groupinstall GROUP
# 升级所有软件包
[root@localhost ~]# yum update
# 升级软件包
[root@localhost ~]# yum update NAME
# 升级软件组
[root@localhost ~]# yum groupupdate GROUP
# 检查需要更新的包
[root@localhost ~]# yum check-update
# 显示软件源所有可用包
[root@localhost ~]# yum list
# 显示系统中已经安装过的包
[root@localhost ~]# yum list installed
# 显示某个包的信息
[root@localhost ~]# yum info NAME
# 显示某个软件组的信息
[root@localhost ~]# yum groupinfo GROUP
# 删除软件包
[root@localhost ~]# yum remove NAME
# 删除软件组
[root@localhost ~]# yum groupremove GROUP
# 清楚操作
[root@localhost ~]# yum clean