linux's docs

10.2.0: 软件安装-源码

1. 源码包安装

1) 安装条件:

  • 源码包(file.c)
    开源程序包,大多用C语言开发,机器无法认识,需要编译。
  • 编译器(gcc)
    安装语句, yum install -y gcc
    编译c语言文件为二进制可执行文件

2) 安装语法:

下载源码包,解压,进入解压出来的目录

  • "./configure" - 配置各种编译参数,并产生Makefile档案;
  • "make clean" - 非必要步骤,作用是避免有其他机器编译文件残留;
  • "make" - 根据编译参数进行编译
    编译出object files; 连接object files; 在当前目录生成二进制执行文件;
  • "make install" - 安装相应文件到指定目录

参数:

  • --prefix 指定安装目录(./configure --prefix 安装路径)
  • --configure --help 可查看更多信息

3) 用法举例(源码安装apache):

# 安装wget,为下载源码包准备工具
yum install wget


# 下载apache源码包,"./configure"报错关键字"APR"

# 习惯将源码包放在约定的目录
cd /usr/local/src
wget http://mirror.nus.edu.sg/apache/httpd/httpd-2.4.10.tar.bz2
tar -xjf httpd-2.4.10.tar.bz2
cd httpd-2.4.10
./configure --prefix=/usr/local/apache2
...省略...
checking for APR... no
configure: error: APR not found.  Please read the documentation.


# 按提示下载并安装APR

cd /usr/local/src
wget http://mirror.nus.edu.sg/apache/apr/apr-1.5.1.tar.bz2
tar -xjf apr-1.5.1.tar.bz2
cd apr-1.5.1
./configure
make
make install


# 再次安装apache,保存提示关键词"APR-util"

cd /usr/local/src/httpd-2.4.10
./configure
...省略...
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.


# 按提示下载并安装"APR-util"

cd /usr/local/src
wget http://mirror.nus.edu.sg/apache/apr/apr-util-1.5.4.tar.bz2
tar -xjf apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4
./configure --with-apr=/usr/local/apr
make
make install


## 再次安装apache,报错关键字"pcre"

# cd /usr/local/src/httpd-2.4.10
# ./configure
...省略...
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/


# 按提示下载安装pcre,错误提示缺少c++

cd /usr/local/src
wget http://sourceforge.net/projects/pcre/files/pcre/8.36/pcre-8.36.tar.bz2
tar -xjf pcre-8.36.tar.bz2
cd pcre-8.36
./configure
configure: error: You need a C++ compiler for C++ support.


# 查询gcc安装情况,用yum安装gcc-c++

# 查看目前gcc版本
rpm -qf $(which gcc)
gcc-4.4.7-4.el6.i686
# gcc包依赖太多,选择yum安装
yum install gcc-c++


# 安装pcre

./configure
make
make install

# 再次安装apache
cd /usr/local/src/httpd-2.4.10
./configure --prefix=/usr/local/apache2
make
make install

Contents