12.2 安装bash
正如第8章所说,Linux下安装软件的方式无非是RPM包安装、yum安装、源码安装3种方式,读者可以任选一种方式。不过,相对来说RPM包安装和yum安装方式比较简单,若再考虑各种包的依赖关系,这两种方式中又属yum安装更为简单。因而这里就不详细介绍这两种安装方法了,下面会具体示范使用源码安装bash的过程。
首先访问http://www.gnu.org/software/bash/bash.html页面,在Downloads中选择一个下载的链接,笔者选择了中国科技大学提供的FTP下载目录:ftp://mirrors.ustc.edu.cngnubash/。
当前很多生产环境的系统中使用的bash版本还是3.2版,读者可以根据实际需要选择具体的版本。在笔者撰写本书时,最新的版本是4.2版本,所以这里使用这个版本来做示范。
第一步:使用wget下载最新的bash源码包,如下所示:
- [root@localhost ~]# wget ftp://mirrors.ustc.edu.cngnubash/bash-4.2.tar.gz --2013-04-11 19:37:41-- ftp://mirrors.ustc.edu.cngnubash/bash-4.2.tar.gz => `bash-4.2.tar.gz'
Resolving mirrors.ustc.edu.cn... 202.141.160.110, 2001:da8:d800:95::110
Connecting to mirrors.ustc.edu.cn|202.141.160.110|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD gnubash ... done.
==> SIZE bash-4.2.tar.gz ... 7009201
==> PASV ... done. ==> RETR bash-4.2.tar.gz ... done.
Length: 7009201 (6.7M)
100%[==========================================>] 7,009,201 1.93M/s in 3.5s 2013-04-11 19:37:46 (1.89 MB/s) - `bash-4.2.tar.gz' saved [7009201]
第二步:解压源码包,并进入生成的目录中。
#
解压后会在当前目录下生成一个bash-4.2
目录
[root@localhost ~]# tar zxvf bash-4.2.tar.gz #
进入目录bash-4.2
[root@localhost ~]# cd bash-4.2
[root@localhost bash-4.2]#
第三步:准备配置(configure)。
最简单的配置方式是直接运行当前目录下的configure,这会将bash安装到usrlocal目录中,不过编译安装软件时,好的习惯是使用—prefix参数指定安装目录。所以这里采用下面的配置方式。该条命令将会产生大量的输出,一开始会检查系统的编译环境以及相关的依赖软件。最常见的错误可能是系统中没有安装gcc造成无法继续(见下面输出内容中画横线的部分),如果是这个原因,使用yum install gcc命令或者参照8.2.4节的安装方式进行安装。如果配置过程出现致命错误会立即退出,请读者注意输出内容中的error部分。
- [root@localhost bash-4.2]# ./configure --prefix=usrlocal/bash4.2
checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu Beginning configuration for bash-4.2-release for i686-pc-linux-gnu checking for gcc... gcc
checking for C compiler default output file name... a.out checking whether the C compiler works... Yes ......(
略去内容)......
#
如果大量的checking
没问题,则配置环境检测通过。如果读者看到如下的输出内容,说明配置成功
configure: creating ./config.status config.status: creating Makefile
config.status: creating builtins/Makefile config.status: creating lib/readline/Makefile config.status: creating lib/glob/Makefile config.status: creating lib/intl/Makefile config.status: creating lib/malloc/Makefile config.status: creating lib/sh/Makefile config.status: creating lib/termcap/Makefile config.status: creating lib/tilde/Makefile config.status: creating doc/Makefile config.status: creating support/Makefile config.status: creating po/Makefile.in config.status: creating examples/loadables/Makefile config.status: creating examples/loadables/perl/Makefile config.status: creating config.h
config.status: executing default-1 commands config.status: creating po/POTFILES
config.status: creating po/Makefile config.status: executing default commands #
如果配置成功,会在当前目录中生成Makefile
[root@localhost bash-4.2]# ll Makefile -rw-r--r-- 1 root root 77119 Apr 11 19:49 Makefile
第四步:正式编译。
#
编译过程会产生大量输出
[root@localhost bash-4.2]# make
rm -f mksyntax
gcc -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"i686"'
-DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"i686-pc-linux-gnu"'
-DCONF_VENDOR='"pc"'
-DLOCALEDIR='"usrlocal/bash4.2/share/locale"'
-DPACKAGE='"bash"' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g -o mksyntax ./mksyntax.c ……(
略去内容)……
第五步:安装。有时在安装前也可以进行测试,但是一般情况下这不是必需的。
#
非必要步骤:测试安装
[root@localhost bash-4.2]# make test
安装
[root@localhost bash-4.2]# make install #
安装其实就是将make
产生的文件复制到指定的目录中,在这里指定的目录就是之前我们用
—prefix
参数指定的usrlocal
,可以在该目录中发现bash4.2
目录
[root@localhost ~]# ls -ld usrlocal/bash4.2/
drwxr-xr-x 4 root root 4096 Apr 11 20:08 usrlocal/bash4.2/
到此为止,最新版本的bash就已经安装好了,确切地说是安装到了usrlocal/bash4.2中。