首页 > 代码库 > 软件包管理之源码编译安装
软件包管理之源码编译安装
编译步骤:
1.#cd SOURCE_CODE
2../configure
作用:
检测编译环境
提供给用户编译配置(通过脚本选项)
--help 帮助信息
--prefix=/usr/local/name 安装路径
二进制
/usr/local/name/bin
/usr/local/name/libexec不允许自动执行,只能被其他程序调用执行
配置文件
/usr/local/name/conf
库文件
/usr/local/name/lib
帮助文档
/usr/local/name/share/man
3.make
默认使用gcc编译器
make依赖于makefile来编译源码
configure脚本 + Makefile.in = makefile
autoconf生成configure脚本
automake生成Makefile.in
4.make install
下面我们以编译安装httpd-2.4.6.tar.bz2为例:
1.解压展开httpd-2.4.6.tar.bz2源码包:
[root@wsh ~]# ls Documents Music Public Videos httpd-2.4.6.tar.bz2 install.log.syslog Desktop Downloads Pictures Templates anaconda-ks.cfg install.log mkscript [root@wsh ~]# tar -xf httpd-2.4.6.tar.bz2 #解压展开源码包到本目录下 [root@wsh ~]# ls Documents Music Public Videos httpd-2.4.6 install.log mkscript Desktop Downloads Pictures Templates anaconda-ks.cfg httpd-2.4.6.tar.bz2 install.log.syslog
2.执行./configure
[root@wsh ~]# cd httpd-2.4.6 #切换到源码所在目录 [root@wsh httpd-2.4.6]# ls ABOUT_APACHE CHANGES Makefile.in README.platforms apache_probes.d configure.in include srclib Apache-apr2.dsw INSTALL Makefile.win ROADMAP build docs libhttpd.dsp support Apache.dsw InstallBin.dsp NOTICE VERSIONING buildconf emacs-style modules test BuildAll.dsp LAYOUT NWGNUmakefile acinclude.m4 config.layout httpd.dsp os BuildBin.dsp LICENSE README ap.d configure httpd.spec server [root@wsh httpd-2.4.6]# ./configure --prefix=/usr/local/apache #执行configure脚本 checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu configure: configure: Configuring Apache Portable Runtime library... configure: checking for APR... no configure: error: APR not found. Please read the documentation. #很不幸运,缺少apr相关包,下面编译安装apr包 [root@wsh ~]# tar -xf apr-1.4.6.tar.bz2 [root@wsh ~]# cd apr-1.4.6 [root@wsh apr-1.4.6]# ./configure --prefix=/usr/local/apr #执行configure脚本,指定安装路径 checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu Configuring APR library Platform: x86_64-unknown-linux-gnu checking for working mkdir -p... yes APR Version: 1.4.6 checking for chosen layout... apr checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no ......... configure: creating ./config.status config.status: creating Makefile config.status: creating include/apr.h config.status: creating build/apr_rules.mk config.status: creating build/pkg/pkginfo config.status: creating apr-1-config config.status: creating apr.pc config.status: creating test/Makefile config.status: creating test/internal/Makefile config.status: creating include/arch/unix/apr_private.h config.status: executing libtool commands rm: cannot remove `libtoolT‘: No such file or directory config.status: executing default commands [root@wsh apr-1.4.6]# make #执行make make[1]: Entering directory `/root/apr-1.4.6‘ /bin/sh /root/apr-1.4.6/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I./include -I/root/apr-1.4.6/include/arch/unix -I./include/arch/unix -I/root/apr-1.4.6/include/arch/unix -I/root/apr-1.4.6/include ............. sed -e ‘s,^\(apr_build.*=\).*$,\1/usr/local/apr/build-1,‘ -e ‘s,^\(top_build.*=\).*$,\1/usr/local/apr/build-1,‘ < build/apr_rules.mk > build/apr_rules.out make[1]: Leaving directory `/root/apr-1.4.6‘ [root@wsh apr-1.4.6]# make install #执行make install make[1]: Entering directory `/root/apr-1.4.6‘ make[1]: Nothing to be done for `local-all‘. make[1]: Leaving directory `/root/apr-1.4.6‘ /root/apr-1.4.6/build/mkdir.sh /usr/local/apr/lib /usr/local/apr/bin /usr/local/apr/build-1 /usr/local/apr/lib/pkgconfig /usr/local/apr/include/apr-1 mkdir /usr/local/apr mkdir /usr/local/apr/lib mkdir /usr/local/apr/bin mkdir /usr/local/apr/build-1 mkdir /usr/local/apr/lib/pkgconfig ........ /usr/bin/install -c -m 644 /root/apr-1.4.6/build/${f} /usr/local/apr/build-1; done /usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk /usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config [root@wsh apr-1.4.6]# ls /usr/local/apr/ #的确生成了相关文件 bin build-1 include lib #上述相同方式编译安装apr-util [root@wsh ~]# tar -xf apr-util-1.4.1.tar.bz2 [root@wsh ~]# cd apr-util-1.4.1 [root@wsh apr-util-1.4.1]# ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking for working mkdir -p... yes APR-util Version: 1.4.1 checking for chosen layout... apr-util checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed Applying apr-util hints file rules for x86_64-unknown-linux-gnu checking for APR... no configure: error: APR could not be located. Please use the --with-apr option. #与上面不同的是,需要使用--with-apr=/usr/local/apr选项 [root@wsh apr-util-1.4.1]# ./configure --with-apr=/usr/local/apr/ --prefix=/usr/local/apr-util #--with-apr指定apr的安装路径 checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking for working mkdir -p... yes ..... config.status: creating include/apu_want.h config.status: creating test/Makefile config.status: creating include/private/apu_config.h config.status: executing default commands [root@wsh apr-util-1.4.1]#make ...... ...... [root@wsh apr-util-1.4.1]#make install ..... ..... [root@wsh apr-util-1.4.1]# ls /usr/local/apr-util/ #生成相关文件 bin include lib
#重新执行httpd的configure脚本: [root@wsh httpd-2.4.6]# ./configure --prefix=/usr/local/apache checking for chosen layout... Apache ......... checking for pcre-config... false configure: error: pcre-config for libpcre not found. PCRE is required and available from #XXOO,继续编译安装pcre包 #步骤同上./configure,make,make install [root@wsh httpd-2.4.6]# ./configure --with-apr-util=/usr/local/apr-util/ --prefix=/usr/local/apache ##--with-apr-util安装路径## checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E ........ config.status: creating build/config_vars.sh config.status: creating include/ap_config_auto.h config.status: executing default commands
[root@wsh httpd-2.4.6]#make ##make## ...... make[2]: Leaving directory `/root/httpd-2.4.6/modules‘ make[2]: Entering directory `/root/httpd-2.4.6/support‘ make[2]: Leaving directory `/root/httpd-2.4.6/support‘ make[1]: Leaving directory `/root/httpd-2.4.6‘ [root@wsh httpd-2.4.6]#make install ##make install## ....... mkdir /usr/local/apache/man mkdir /usr/local/apache/man/man1 mkdir /usr/local/apache/man/man8 mkdir /usr/local/apache/manual make[1]: Leaving directory `/root/httpd-2.4.6‘ [root@wsh httpd-2.4.6]# ls /usr/local/apache/ ##安装后生成的文件## bin build cgi-bin conf error htdocs icons include logs man manual modules 1.将/usr/local/apache/bin加入PATH: [root@wsh apache]# vim /etc/profile.d/apache.sh #编辑配置文件,生成环境变量,永久生效 export PATH=/usr/local/apache/bin:$PATH [root@wsh apache]# . /etc/profile.d/apache.sh #source配置文件 [root@wsh apache]# echo $PATH #查看PATH环境变量 /usr/local/apache/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@wsh apache]# apachectl start #启动服务 [root@wsh apache]# hash #查看,确实是该路径下的apachectl命令 #在/usr/sbin/apachectl,也有该命令 hitscommand 1/usr/local/apache/bin/apachectl [root@wsh apache]# ifconfig | grep "inet addr" | cut -d: -f2 | cut -d‘ ‘ -f 1 | grep -v "127.0.0.1" ##获取本机ip地址 192.168.155.3
浏览器浏览该ip地址:
2.如果源码编译安装的软件包生成了lib,则需要将lib所在路径加入到
vim /etc/ld.so/conf.d/apache.conf 写入:/usr/local/apache/lib # ldconfig -v: 重新搜索当前系统上所有库文件搜索路径下的库文件,并生成缓存/etc/ld.so.cache
3.配置/etc/man.conf:
vim /etc/man.conf 写入:PATH /usr/local/apache/man
4.头文件路径:
[root@www apache]# ln -s /usr/local/apache/include/ /usr/include/apache#符号链接至/usr/include [root@www apache]# ls -l /usr/include/apache lrwxrwxrwx. 1 root root 26 May 23 23:38 /usr/include/apache -> /usr/local/apache/include/
本文出自 “大灰狼” 博客,请务必保留此出处http://huifei1314.blog.51cto.com/4681402/1416475