概述
安装一个源码包,通常需要三个步骤:
1、./configure
2、 make
3、 make install
一般用阅读源码包的帮助文档提供的安装步骤进行安装。通常是 INSTALL 或 README 文件。
以安装nginx为例,以下是安装的全过程:
[root@localhost ~]# cd /usr/local/src
####
#### 下载 nginx 源码包
[root@localhost src]# wget http://nginx.org/download/nginx-1.14.2.tar.gz
--2019-02-20 17:30:14-- http://nginx.org/download/nginx-1.14.2.tar.gz
正在解析主机 nginx.org (nginx.org)... 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3
正在连接 nginx.org (nginx.org)|95.211.80.227|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://117.143.109.201/cache/nginx.org/download/nginx-1.14.2.tar.gz?ich_args2=39-20173004019369_5b6f2632bf91b3cdae35405cfb43338b_10001002_9c89612cd1c6f4d1963f518939a83798_ff478ef610d500dd7f20fe13dd251d7b [跟随至新的 URL]
--2019-02-20 17:30:14-- http://117.143.109.201/cache/nginx.org/download/nginx-1.14.2.tar.gz?ich_args2=39-20173004019369_5b6f2632bf91b3cdae35405cfb43338b_10001002_9c89612cd1c6f4d1963f518939a83798_ff478ef610d500dd7f20fe13dd251d7b
正在连接 117.143.109.201:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1015384 (992K) [application/octet-stream]
正在保存至: “nginx-1.14.2.tar.gz”
100%[======================================>] 1,015,384 --.-K/s 用时 0.1s
2019-02-20 17:30:15 (7.84 MB/s) - 已保存 “nginx-1.14.2.tar.gz” [1015384/1015384])
[root@localhost src]# ls
nginx-1.14.2.tar.gz
####
#### 解压
[root@localhost src]# tar -xvf nginx-1.14.2.tar.gz
nginx-1.14.2/
# 解压过程省略......
[root@localhost src]#
[root@localhost src]# cd nginx-1.14.2/
####
#### ./configure
[root@localhost nginx-1.14.2]# ./configure
checking for OS
+ Linux 3.10.0-862.el7.x86_64 x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
checking for gcc -pipe switch ... found
# checking 过程省略...
checking for PCRE library in /opt/local/ ... not found
# 报错:HTTP rewrite 模块 需要 PCRE 库
./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.
### 安装 PCRE 库
root@localhost nginx-1.14.2]# yum install -y pcre-devel
# 安装过程省略...
[root@localhost nginx-1.14.2]#
####
#### 重新执行 ./configure
./configure: error: the HTTP gzip module requires the zlib library.
### 安装 zlib
[root@localhost nginx-1.14.2]# yum install -y zlib-devel
# 安装过程省略...
#### 重新执行 ./configure
# checking 过程省略...
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
####
#### make
# make 过程省略..
make[1]: 离开目录“/usr/local/src/nginx-1.14.2”
# echo $? 检查返回结果 0 成功
[root@localhost nginx-1.14.2]# echo $?
0
####
#### make install
[root@localhost nginx-1.14.2]# make install
make -f objs/Makefile install
make[1]: 进入目录“/usr/local/src/nginx-1.14.2”
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
|| mv '/usr/local/nginx/sbin/nginx' \
'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
|| mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
|| cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' \
|| cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params \
'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
|| mkdir -p '/usr/local/nginx/logs'
make[1]: 离开目录“/usr/local/src/nginx-1.14.2”
# 安装完成
# 默认安装路径 /usr/local/nginx
# 若想指定安装路径 在第1步./configure --prefix=/xxx 来指定安装路径
[root@localhost nginx]# pwd
/usr/local/nginx
[root@localhost nginx]# ls
conf html logs sbin
[root@localhost nginx]# cd sbin
# 查看版本
[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.14.2
# 配置到环境变量
[root@localhost sbin]# vim /etc/profile.d/nginx.sh
# 插入 export PATH=/usr/local/nginx/sbin:$PATH 保存退出
[root@localhost sbin]# . /etc/profile.d/nginx.sh
[root@localhost sbin]# echo $PATH
/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
# 测试 查看版本
[root@localhost sbin]# nginx -v
nginx version: nginx/1.14.2
# 启动 nginx
[root@localhost nginx]# nginx
[root@localhost nginx]# ps -ef | grep nginx
root 68099 1 0 18:02 ? 00:00:00 nginx: master process nginx
nobody 68100 68099 0 18:02 ? 00:00:00 nginx: worker process
root 68102 5657 0 18:02 pts/0 00:00:00 grep --color=auto nginx
# 测试 OK
[root@localhost nginx]# wget http://192.168.190.139
--2019-02-20 18:04:02-- http://192.168.190.139/
正在连接 192.168.190.139:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:612 [text/html]
其他问题
1. ./configure: error: C compiler cc is not found
[root@VM_0_2_centos nginx-1.15.10]# yum install gcc gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-36.el7_6.1 will be installed
--> Processing Dependency: libgomp = 4.8.5-36.el7_6.1 for package: gcc-4.8.5-36.el7_6.1.x86_64
--> Processing Dependency: cpp = 4.8.5-36.el7_6.1 for package: gcc-4.8.5-36.el7_6.1.x86_64
--> Processing Dependency: libgcc >= 4.8.5-36.el7_6.1 for package: gcc-4.8.5-36.el7_6.1.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-36.el7_6.1.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-36.el7_6.1.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-36.el7_6.1.x86_64
---> Package gcc-c++.x86_64 0:4.8.5-36.el7_6.1 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-36.el7_6.1 for package: gcc-c++-4.8.5-36.el7_6.1.x86_64
--> Processing Dependency: libstdc++ = 4.8.5-36.el7_6.1 for package: gcc-c++-4.8.5-36.el7_6.1.x86_64
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-36.el7_6.1 will be installed
---> Package glibc-devel.x86_64 0:2.17-260.el7_6.3 will be installed
--> Processing Dependency: glibc-headers = 2.17-260.el7_6.3 for package: glibc-devel-2.17-260.el7_6.3.x86_64
--> Processing Dependency: glibc = 2.17-260.el7_6.3 for package: glibc-devel-2.17-260.el7_6.3.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-260.el7_6.3.x86_64
---> Package libgcc.x86_64 0:4.8.5-28.el7 will be updated
---> Package libgcc.x86_64 0:4.8.5-36.el7_6.1 will be an update
---> Package libgomp.x86_64 0:4.8.5-28.el7 will be updated
---> Package libgomp.x86_64 0:4.8.5-36.el7_6.1 will be an update
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package libstdc++.x86_64 0:4.8.5-28.el7 will be updated
---> Package libstdc++.x86_64 0:4.8.5-36.el7_6.1 will be an update
---> Package libstdc++-devel.x86_64 0:4.8.5-36.el7_6.1 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package glibc.x86_64 0:2.17-222.el7 will be updated
--> Processing Dependency: glibc = 2.17-222.el7 for package: glibc-common-2.17-222.el7.x86_64
---> Package glibc.x86_64 0:2.17-260.el7_6.3 will be an update
---> Package glibc-headers.x86_64 0:2.17-260.el7_6.3 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-260.el7_6.3.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-260.el7_6.3.x86_64
--> Running transaction check
---> Package glibc-common.x86_64 0:2.17-222.el7 will be updated
---> Package glibc-common.x86_64 0:2.17-260.el7_6.3 will be an update
---> Package kernel-headers.x86_64 0:3.10.0-957.10.1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Installing:
gcc x86_64 4.8.5-36.el7_6.1 updates 16 M
gcc-c++ x86_64 4.8.5-36.el7_6.1 updates 7.2 M
Installing for dependencies:
cpp x86_64 4.8.5-36.el7_6.1 updates 5.9 M
glibc-devel x86_64 2.17-260.el7_6.3 updates 1.1 M
glibc-headers x86_64 2.17-260.el7_6.3 updates 683 k
kernel-headers x86_64 3.10.0-957.10.1.el7 updates 8.0 M
libmpc x86_64 1.0.1-3.el7 os 51 k
libstdc++-devel x86_64 4.8.5-36.el7_6.1 updates 1.5 M
mpfr x86_64 3.1.1-4.el7 os 203 k
Updating for dependencies:
glibc x86_64 2.17-260.el7_6.3 updates 3.7 M
glibc-common x86_64 2.17-260.el7_6.3 updates 12 M
libgcc x86_64 4.8.5-36.el7_6.1 updates 102 k
libgomp x86_64 4.8.5-36.el7_6.1 updates 157 k
libstdc++ x86_64 4.8.5-36.el7_6.1 updates 305 k
Transaction Summary
========================================================================================================
Install 2 Packages (+7 Dependent packages)
Upgrade ( 5 Dependent packages)
Total download size: 57 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/14): cpp-4.8.5-36.el7_6.1.x86_64.rpm | 5.9 MB 00:00:01
(2/14): gcc-c++-4.8.5-36.el7_6.1.x86_64.rpm | 7.2 MB 00:00:00
(3/14): glibc-2.17-260.el7_6.3.x86_64.rpm | 3.7 MB 00:00:00
(4/14): glibc-common-2.17-260.el7_6.3.x86_64.rpm | 12 MB 00:00:00
(5/14): glibc-devel-2.17-260.el7_6.3.x86_64.rpm | 1.1 MB 00:00:00
(6/14): glibc-headers-2.17-260.el7_6.3.x86_64.rpm | 683 kB 00:00:00
(7/14): kernel-headers-3.10.0-957.10.1.el7.x86_64.rpm | 8.0 MB 00:00:00
(8/14): gcc-4.8.5-36.el7_6.1.x86_64.rpm | 16 MB 00:00:02
(9/14): libgcc-4.8.5-36.el7_6.1.x86_64.rpm | 102 kB 00:00:00
(10/14): libgomp-4.8.5-36.el7_6.1.x86_64.rpm | 157 kB 00:00:00
(11/14): libstdc++-4.8.5-36.el7_6.1.x86_64.rpm | 305 kB 00:00:00
(12/14): libstdc++-devel-4.8.5-36.el7_6.1.x86_64.rpm | 1.5 MB 00:00:00
(13/14): libmpc-1.0.1-3.el7.x86_64.rpm | 51 kB 00:00:00
(14/14): mpfr-3.1.1-4.el7.x86_64.rpm | 203 kB 00:00:00
--------------------------------------------------------------------------------------------------------
Total 20 MB/s | 57 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : libgcc-4.8.5-36.el7_6.1.x86_64 1/19
Updating : glibc-2.17-260.el7_6.3.x86_64 2/19
Updating : glibc-common-2.17-260.el7_6.3.x86_64 3/19
Installing : mpfr-3.1.1-4.el7.x86_64 4/19
Installing : libmpc-1.0.1-3.el7.x86_64 5/19
Updating : libstdc++-4.8.5-36.el7_6.1.x86_64 6/19
Installing : libstdc++-devel-4.8.5-36.el7_6.1.x86_64 7/19
Installing : cpp-4.8.5-36.el7_6.1.x86_64 8/19
Updating : libgomp-4.8.5-36.el7_6.1.x86_64 9/19
Installing : kernel-headers-3.10.0-957.10.1.el7.x86_64 10/19
Installing : glibc-headers-2.17-260.el7_6.3.x86_64 11/19
Installing : glibc-devel-2.17-260.el7_6.3.x86_64 12/19
Installing : gcc-4.8.5-36.el7_6.1.x86_64 13/19
Installing : gcc-c++-4.8.5-36.el7_6.1.x86_64 14/19
Cleanup : libstdc++-4.8.5-28.el7.x86_64 15/19
Cleanup : libgomp-4.8.5-28.el7.x86_64 16/19
Cleanup : glibc-2.17-222.el7.x86_64 17/19
Cleanup : glibc-common-2.17-222.el7.x86_64 18/19
Cleanup : libgcc-4.8.5-28.el7.x86_64 19/19
Verifying : glibc-devel-2.17-260.el7_6.3.x86_64 1/19
Verifying : gcc-4.8.5-36.el7_6.1.x86_64 2/19
Verifying : glibc-common-2.17-260.el7_6.3.x86_64 3/19
Verifying : libstdc++-4.8.5-36.el7_6.1.x86_64 4/19
Verifying : glibc-2.17-260.el7_6.3.x86_64 5/19
Verifying : kernel-headers-3.10.0-957.10.1.el7.x86_64 6/19
Verifying : mpfr-3.1.1-4.el7.x86_64 7/19
Verifying : libgomp-4.8.5-36.el7_6.1.x86_64 8/19
Verifying : gcc-c++-4.8.5-36.el7_6.1.x86_64 9/19
Verifying : libmpc-1.0.1-3.el7.x86_64 10/19
Verifying : libstdc++-devel-4.8.5-36.el7_6.1.x86_64 11/19
Verifying : libgcc-4.8.5-36.el7_6.1.x86_64 12/19
Verifying : cpp-4.8.5-36.el7_6.1.x86_64 13/19
Verifying : glibc-headers-2.17-260.el7_6.3.x86_64 14/19
Verifying : libgomp-4.8.5-28.el7.x86_64 15/19
Verifying : glibc-common-2.17-222.el7.x86_64 16/19
Verifying : libstdc++-4.8.5-28.el7.x86_64 17/19
Verifying : glibc-2.17-222.el7.x86_64 18/19
Verifying : libgcc-4.8.5-28.el7.x86_64 19/19
Installed:
gcc.x86_64 0:4.8.5-36.el7_6.1 gcc-c++.x86_64 0:4.8.5-36.el7_6.1
Dependency Installed:
cpp.x86_64 0:4.8.5-36.el7_6.1 glibc-devel.x86_64 0:2.17-260.el7_6.3
glibc-headers.x86_64 0:2.17-260.el7_6.3 kernel-headers.x86_64 0:3.10.0-957.10.1.el7
libmpc.x86_64 0:1.0.1-3.el7 libstdc++-devel.x86_64 0:4.8.5-36.el7_6.1
mpfr.x86_64 0:3.1.1-4.el7
Dependency Updated:
glibc.x86_64 0:2.17-260.el7_6.3 glibc-common.x86_64 0:2.17-260.el7_6.3
libgcc.x86_64 0:4.8.5-36.el7_6.1 libgomp.x86_64 0:4.8.5-36.el7_6.1
libstdc++.x86_64 0:4.8.5-36.el7_6.1
Complete!