Linux学习(二十)软件安装与卸载(三)源码包安装

一、概述

源码包安装的优点在于它自由程度比较高,可以指定目录与组件。再有,你要是能改源码也可以。

二、安装方法

步骤

1.从官网或者信任站点下载源码包

[root@localhost ~]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz

2.把下载的安装包解压到/usr/local/src目录下

tar zxvf httpd-2.2.34.tar.gz -C /usr/local/src/

3.编译

在编译之前,我们看看INSTALL文件和README文件。

less INSTALL
#文件里有安装的方法
 $ ./configure --prefix=PREFIX
     $ make
     $ make install
     $ PREFIX/bin/apachectl start

     NOTES: * Replace PREFIX with the filesystem path under which 
              Apache should be installed.  A typical installation
              might use "/usr/local/apache2" for PREFIX (without the
              quotes).

我们也可以使用./configure --help查看帮助。

[root@localhost httpd-2.2.34]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:

现在我们根据INSTALL文件里的提示安装。

[root@localhost httpd-2.2.34]# ./configure --prefix=/usr/local/apache2/
checking for chosen layout... Apache
checking for working mkdir -p... yes
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 Apache Portable Runtime library ...

checking for APR... reconfig
configuring package in srclib/apr now
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.5.2
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/httpd-2.2.34/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
configure failed for srclib/apr

使用echo $?命令查看上一步命令是否执行成功。

[root@localhost httpd-2.2.34]# echo $?
1

1说明失败,0说明成功。

在网上查了一下资料,说碰到这种情况安装gcc就好了。

yum install -y gcc

重新编译,然后看是否安装成功。

[root@localhost httpd-2.2.34]# ./configure --prefix=/usr/local/apache2/
[root@localhost httpd-2.2.34]# echo $?
0

输出0说明编译成功了。我们发现目录里生成了Makefile文件。我们用stat命令看一下。

[root@localhost httpd-2.2.34]# stat Makefile
  File: "Makefile"
  Size: 8954          Blocks: 24         IO Block: 4096   普通文件
Device: 803h/2051d    Inode: 927753      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-11-10 18:42:24.171229769 +0800
Modify: 2017-11-10 18:42:24.173229769 +0800
Change: 2017-11-10 18:42:24.173229769 +0800

 

是刚刚生成的。 

有了Makefile之后,我们就可以执行编译了。编译命令是make。

make

 

make一般执行的时间比较长。等结束之后我们再用echo $?看看是否成功。

[root@localhost httpd-2.2.34]# echo $?
0

 

make成功了。

4.安装

安装的命令也很简单:make install。

make install
[root@localhost httpd-2.2.34]# echo $?
0

说明最后一步也成功了。

三、总结

编译安装的主要步骤是

1.下载

2.将文件解压到/usr/local/src/

3.查看INSTALL文件和README文件,使用./configure --help查看帮助

4.编译

5.安装

每一步执行后可以使用echo $?看看是否执行成功。

posted @ 2017-11-10 11:10  andyliud  阅读(233)  评论(0编辑  收藏  举报