2023.6.6源码安装包管理
1.源码包基本概述
在 linux 环境下⾯安装源码包是⽐较常⻅的, 早起运维管理⼯作中,⼤部分软件都是通过源码安装的。那么安装⼀
个源码包,是需要我们⾃⼰把源代码编译成⼆进制的可执⾏⽂件。
源码包的编译⽤到了 linux 系统⾥的编译器,通常源码包都是⽤C语⾔开发的,这也是因为C语⾔为linux上最标准
的程序语⾔。Linux上的C语⾔编译器叫做gcc,利⽤它就可以把C语⾔变成可执⾏的⼆进制⽂件。所以如果你的机器
上没有安装gcc就没有办法去编译源码。可以使⽤ yum install -y gcc 来完成安装。
1.使⽤源码包的好处
1.⾃定义修改源代码
2.定制需要的相关功能
3.新版软件优先更新源码
2.源码包如何获取
官⽅⽹站, 可以获得最新的软件包
Apache官⽅⽹站
Nginx官⽅⽹站
github
3.源码包如何安装
编译环境 gcc、make
依赖环境pcre、openssl
准备对应软件 nginx-1.12.tar.gz
源码安装三步曲(常⻅)
第⼀步: ./configure(定制组件)
a.指定安装路径,例如 --prefix=/soft/nginx-1.12
b.启⽤或禁⽤某项功能, 例如 --enable-ssl
c.和其它软件关联,例如--with-pcre
d.检查安装环境,例如是否有编译器 gcc,是否满⾜软件的依赖需求
e.检测通过后⽣成Makefile⽂件
第⼆步: make
1.执⾏make命令进⾏编辑, 可以使⽤-j指定CPU编译
2.按Makefile⽂件进⾏编译, 编译成可执⾏⼆进制⽂件
3.⽣成各类模块和主程序。
第三步: make install
1.执⾏make install
2.按Makefile定义好的路径拷⻉⾄安装⽬录中。
上⾯介绍的源码三部曲不能百分百通⽤于所有源码包, 也就是说源码包的安装并⾮存在标准安装步骤。
建议:拿到源码包解压后,然后进⼊到⽬录找相关的帮助⽂档,通常会以 INSTALL 或者 README 为⽂件名。
4.源码包编译实例
下⾯通过编译Nginx来深⼊理解源码包安装
//1.基础环境准备
[root@node1 ~]# yum install -y gcc make wget
//2.下载源码包(源码包⼀定要上官⽅站点下载,其他站点不安全)
[root@node1 ~]# mkdir -p /soft/src
[root@node1 src]# cd /soft/src
[root@node1 src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
//3.解压源码包,并进⼊相应⽬录
[root@node1 src]# tar xf nginx-1.12.2.tar.gz
[root@node1 src]# cd nginx-1.12.2
//4.配置相关的选项,并⽣成Makefile
[root@node1 nginx-1.12.2]# ./configure --help|head
--help print this message
--prefix=PATH set installation prefix
--sbin-path=PATH set nginx binary pathname
--modules-path=PATH set modules path
--conf-path=PATH set nginx.conf pathname
--error-log-path=PATH set error log pathname
--pid-path=PATH set nginx.pid pathname
--lock-path=PATH set nginx.lock pathname
//后⾯的内容省略了,使⽤ ./configure --help 命令查看可以使⽤的选项。
//⼀般常⽤的有 --prefix=PREFIX 这个选项的意思是定义软件包安装到哪⾥。
//建议,源码包都是安装在/soft/⽬录下。
//5.指定编译参数
[root@node1 nginx-1.12.2]# ./configure --prefix=/soft/nginx-1.12.2
//6.验证这⼀步命令是否成功, ⾮0都都不算成功
[root@node1 nginx-1.12.2]# echo $?
0
//7.编译并安装
[root@node1 nginx-1.12.2]# make
[root@node1 nginx-1.12.2]# make install
[root@node1 nginx-1.12.2]# echo $?
源码编译报错信息处理
checking for C compiler ... not found ./configure: error: C compiler cc is not found
//解决⽅案
# yum -y install gcc gcc-c++ make
vx: WingspanGovx: WingspanGo
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
//解决⽅案
# yum install -y pcre-devel
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without
http_gzip_module option, or install the zlib library into the
system, or build the zlib library statically from the source with
nginx by using --with-zlib=<path> option.
//解决⽅案:
# yum -y install zlib-devel
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL
library into the system, or build the OpenSSL library statically
from the source with nginx by using --with-openssl=<path> option.
//解决⽅案
# yum -y install openssl-devel
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律