虽然现在linux的软件包安装有很多方式,(最常用的有  rpm   yum)但他们也还是有各自的优点和缺点的,当然用什么安装方式根据个人的需求而定,之前写过一篇关于软件包安装的,现在在给大家介绍一种功能更为强大的安装方式;

主要适合安装比较新的软件

   首先介绍一下源码安装的顺序

   当我们从网站上下载了需要的最新的软件包之后所要做的第一步肯定是要进行解压拆包了,因为我们下载的都是压塑包,记得在拆解时一定要把拆解的东西放在一个自己找得到的有比较常用的地方,便于需找,进行安装时也会更方便,在对文件进行拆包时需要指明安装目录和配置文件的存放目录,然后进行安装就可以,但不会是一帆风顺的,在安装时你可能会遇到很多的问题,一个一个把他解决就行了,虽然麻烦但也是很重要的,下面以http的安装为例介绍一下源码安装的具体过程以及有可能遇到的问题

源码安装:

#####################安装时只要具备以下四种环境就可以进行安装否则缺少哪一种就要安装哪一种

[root@localhost ~]# yum grouplist |less

Trying other mirror.

Loaded plugins: rhnplugin, security

Setting up Group Process

Installed Groups:

  Administration Tools

  Authoring and Publishing

  Development Libraries

  Development Tools

  Editors

  GNOME Desktop Environment

  GNOME Software Development

  Games and Entertainment

  Graphical Internet

  Graphics

  Legacy Network Server

  Legacy Software Development

  Legacy Software Support

  Mail Server

  Network Servers

  Office/Productivity

  Printing Support

  Server Configuration Tools

 Legacy Software Development

  Legacy Software Support

  Mail Server

  Network Servers

  Office/Productivity

  Printing Support

  Server Configuration Tools

  Sound and Video

  System Tools

  Text-based Internet

  X Software Development

#####################源码安装时有两种库文件:    

/lib

/usr/lib

#####################动态库:效率低,升级库时对代码无影响

#####################静态库:效率高,  作为代码的一部分参加编译,在升级时会有影响( 一般以 .a   结尾)

#####################头文件:

/include  

/uer/include

##################### 我们的的源码一般是这种格式的  .tar.gz   .tar.bz2    因此我们#####################要先对源码进行拆解

#####################拆解位置:  /usr/local/src

#####################安装位置:  /usr/local/文件名称

./configure选项:

--prefix   指明安装目录

--sysconfdir  指明配置文件存放的位置

--enable     打开选项

--disable     关闭选项

源码安装httpd-2.4   下载网址http://httpd.aparche.org

#####################httpd 的源码安装文件导入到linux/root目录下

#####################查看:文件是否导入

[root@localhost ~]# ll

total 6524

-rw------- 1 root root    1161 Aug 10 19:13 anaconda-ks.cfg

-rw-r--r-- 1 root root  982243 Aug 13 14:05 apr-1.4.6.tar.gz

-rw-r--r-- 1 root root  829779 Aug 13 14:05 apr-util-1.5.1.tar.gz

-rw-r--r-- 1 root root 4780289 Aug 13 14:05 httpd-2.4.4.tar.bz2

-rw-r--r-- 1 root root   38446 Aug 10 19:09 install.log

-rw-r--r-- 1 root root    3995 Aug 10 18:59 install.log.syslog

#####################httpd-2.4.4.tar.bz2进行拆解并放在 /usr/local/src目录下

[root@localhost ~]# tar  -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/

[root@localhost ~]# cd /usr/local/src

[root@localhost src]# ll

total 4

drwxr-xr-x 11 501 games 4096 Feb 18 15:28 httpd-2.4.4

[root@localhost src]# cd httpd-2.4.4/

[root@localhost httpd-2.4.4]# ls

ABOUT_APACHE     configure.in    modules

acinclude.m4     docs            NOTICE

Apache-apr2.dsw  emacs-style     NWGNUmakefile

Apache.dsw       httpd.dsp       os

apache_probes.d  httpd.spec      README

ap.d             include         README.platforms

build            INSTALL         ROADMAP

BuildAll.dsp     InstallBin.dsp  server

BuildBin.dsp     LAYOUT          srclib

buildconf        libhttpd.dsp    support

CHANGES          LICENSE         test

config.layout    Makefile.in     VERSIONING

configure        Makefile.win

#####################指明安装目录和配置文档的目录

[root@localhost httpd-2.4.4]# ./configure --prefix=/sur/local/apache --sysconfdir=/etc/apache

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... i686-pc-linux-gnu

checking host system type... i686-pc-linux-gnu

checking target system type... i686-pc-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@localhost httpd-2.4.4]# rpm -qa |grep -i apr

xorg-x11-drv-dynapro-1.1.0-2

apr-1.2.7-11.el5_3.1

apr-util-1.2.7-7.el5_3.2

#####################可以看到已经安装了但是还少了一个关于库文件的安装包没有装

安装

[root@localhost ~]# rpm -ivh /mnt/cdrom/Server/apr-devel-1.2.7-11.el5_3.1.i386.rpm

Preparing...                ########################################### [100%]

  1:apr-devel              ########################################### [100%]

#####################此时在执行httpd的安装配置

[root@localhost ~]# cd /usr/local/src

[root@localhost src]# ll

total 4

drwxr-xr-x 11 501 games 4096 Aug 13 14:34 httpd-2.4.4

[root@localhost src]# cd httpd-2.4.4/

[root@localhost httpd-2.4.4]# ./configure --prefix=/sur/local/apache --sysconfdir=/etc/apache

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... i686-pc-linux-gnu

checking host system type... i686-pc-linux-gnu

checking target system type... i686-pc-linux-gnu

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... configure: WARNING: APR version 1.4.0 or later is required, found 1.2.7

configure: WARNING: skipped APR at apr-1-config, version not acceptable

no

configure: error: APR not found.  Please read the documentation.

#####################可以看到 APR的版本过低现在我们去升级APR 的版本,版本必须#####################1.4.0及以上的版本

#####################安装 apr的相关软件

[root@localhost ~]# tar -zxvf apr-1.4.6.tar.gz  -C /usr/local/src

[root@localhost ~]# tar -zxvf apr-util-1.5.1.tar.gz  -C /usr/local/src

#####################

#####################安装 apr的配置文件

[root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr

[root@localhost apr-1.4.6]# make install

进入系统的库文件下为apr的库文件创建连接文件

[root@localhost include]# ln -s /usr/local/apr/include/apr-1/*  .

[root@localhost include]# cd /etc/ld.so.conf.d

[root@localhost ld.so.conf.d]# vim apr.conf

/usr/local/apr/lib

#####################更新缓存并查看

[root@localhost ld.so.conf.d]# ldconfig

[root@localhost ld.so.conf.d]# ldconfig -pv |grep apr

libgstdataprotocol-0.10.so.0 (libc6) => /usr/lib/libgstdataprotocol-0.10.so.0

libaprutil-1.so.0 (libc6) => /usr/lib/libaprutil-1.so.0

libapr-1.so.0 (libc6) => /usr/local/apr/lib/libapr-1.so.0

libapr-1.so.0 (libc6) => /usr/lib/libapr-1.so.0

libapr-1.so (libc6) => /usr/local/apr/lib/libapr-1.so

libapr-1.so (libc6) => /usr/lib/libapr-1.so

#####################安装apr的工具包

  [root@localhost apr-util-1.5.1]#./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config          

[root@localhost apr-util-1.5.1]# make

[root@localhost apr-util-1.5.1]# make install

#####################再次安装httpd的配置文件

[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/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

checking build system type... i686-pc-linux-gnu

checking host system type... i686-pc-linux-gnu

checking target system type... i686-pc-linux-gnu

configure:

configure: Configuring Apache Portable Runtime library...

configure:

checking for APR... yes

 setting CC to "gcc"

 setting CPP to "gcc -E"

 setting CFLAGS to " -g -O2 -pthread"

 setting CPPFLAGS to " -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE"

 setting LDFLAGS to " "

configure:

configure: Configuring Apache Portable Runtime Utility library...

configure:

checking for APR-util... yes

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

checking how to run the C preprocessor... gcc -E

checking for gcc option to accept ISO C99... -std=gnu99

checking for pcre-config... false

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

#####################可以看到pcre 出错

#####################查看 pcre 有没有安装

[root@localhost httpd-2.4.4]# rpm -qa |grep pcre

pcre-6.6-2.el5_1.7

#####################可以看他的库文件没有安装

#####################安装pcre的库文件安装包

[root@localhost httpd-2.4.4]# rpm -ivh /mnt/cdrom/Server/pcre-devel-6.6-2.el5_1.7.i386.rpm

Preparing...                ########################################### [100%]

  1:pcre-devel             ########################################### [100%]

#####################

#####################再次执行httpd的配置文件

[root@localhost httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/

#####################成功

[root@localhost httpd-2.4.4]# make

[root@localhost httpd-2.4.4]# make install

#####################httpde 的头文件创建链接文件

[root@localhost apache]# cd /usr/include

[root@localhost include]# ln -s /usr/local/apache/include/* .

#####################httpd 的库文件创建链接文件

[root@localhost include]# cd /etc/ld.so.conf.d

[root@localhost ld.so.conf.d]# vim apache.conf

/usr/local/apache/modules

~                            

#####################重新加载

[root@localhost ld.so.conf.d]# ldconfig

#####################此时http已经安装成功了