Linux使用源码安装软件示例

来源:互联网 发布:linux sendmail smtp 编辑:程序博客网 时间:2024/05/21 10:05

Linux使用源码安装软件示例

在Linux下安装一个软件可以使用rpm/yum安装也可以使用源码安装。

源码解压缩后放置在哪里?

生成的可执行文件放置在哪里?

……

下面看一个简单的使用源码安装软件的例子:

(注:这个例子来自于《鸟哥的Linux私房菜》,下面是我实践的过程)

Tarball:ntp-4.2.8p10.tar.gz

1.将Tarball放置在/root目录下:

[root@localhost ~]# lltotal 6928-rw-------. 1 root root    2692 Apr 13  2017 anaconda-ks.cfg……-rw-r--r--. 1 root root 6998648 Apr 12 17:08 ntp-4.2.8p10.tar.gz……

2.将Tarball解压缩在/usr/local/src下:

[root@localhost ~]# cd /usr/local/src/[root@localhost src]# tar zxvf /root/ntp-4.2.8p10.tar.gz ntp-4.2.8p10/ntp-4.2.8p10/packageinfo.shntp-4.2.8p10/README.pullrequestsntp-4.2.8p10/configure……

注意Tarball中包含的configure,其可以检测运行环境,生成makefile。

[root@localhost src]# lltotal 4drwxrwsr-x. 23 427 6011 4096 Mar 21 07:47 ntp-4.2.8p10[root@localhost src]# cd ntp-4.2.8p10/[root@localhost ntp-4.2.8p10]# lltotal 7044-rw-rw-r--.  1 427 6011   50020 Mar 21 07:37 aclocal.m4drwxrwsr-x.  2 427 6011    4096 Mar 21 07:47 adjtimed-rw-rw-r--.  1 427 6011     605 Jun 22  2011 bincheck.mf-rwxrwxr-x.  1 427 6011    4801 Jun 17  2015 bootstrap-rwxrwxr-x.  1 427 6011    4239 Dec 23  2014 build-rw-rw-r--.  1 427 6011  242006 Mar 21 06:34 ChangeLog-rw-rw-rw-.  1 427 6011     374 Jan  8  2012 check-libopts.mfdrwxrwsr-x.  2 427 6011    4096 Mar 21 07:47 clockstuff-rw-rw-r--.  1 427 6011 5225786 Feb  1 04:41 CommitLog-rw-rw-r--.  1 427 6011  195223 Jan  4  2007 CommitLog-4.1.0drwxrwsr-x.  2 427 6011    4096 Jan 31 23:19 conf-rw-rw-r--.  1 427 6011   42801 Mar 21 07:41 config.h.in-rwxrwxr-x.  1 427 6011  937829 Mar 21 07:37 configure……

3.使用configure检查环境并生成makefile:

[root@localhost ntp-4.2.8p10]# ./configure --prefix=/usr/local/ntpchecking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for a thread-safe mkdir -p... /bin/mkdir -pchecking for gawk... gawkchecking whether make sets $(MAKE)... yeschecking whether make supports nested variables... yeschecking whether make supports nested variables... (cached) yeschecking build system type... i686-pc-linux-gnuchecking host system type... i686-pc-linux-gnuchecking for style of include used by make... GNUchecking for cc... cc……checking for sys/types.h... yeschecking for sys/stat.h... yeschecking for stdlib.h... yeschecking for string.h... yeschecking for memory.h... yeschecking for strings.h... yes……configure: creating ./config.statusconfig.status: creating Makefileconfig.status: creating adjtimed/Makefile……

使用configure会检查编译器、链接器、头文件等等,最终生成makefile文件。

4.可以先make clean下(不是必要步骤,但是可以执行下,安全点):

[root@localhost ntp-4.2.8p10]# make cleanMaking clean in sntpmake[1]: Entering directory `/usr/local/src/ntp-4.2.8p10/sntp'Making clean in includemake[2]: Entering directory `/usr/local/src/ntp-4.2.8p10/sntp/include'rm -rf .libs _libs……

5.执行make进行源码编译:

[root@localhost ntp-4.2.8p10]# makeCompiling with GCC now generates lots of new warnings.Don't be concerned. They're just warnings.Don't send bug reports about the warnings, either.Feel free to send patches that fix these warnings, though.cd ./html && \    ../scripts/build/checkHtmlFileDatescd . && \    ./scripts/build/checkChangeLogmake  all-recursivemake[1]: Entering directory `/usr/local/src/ntp-4.2.8p10'Making all in sntp……

6.make install安装到指定目录:

[root@localhost ntp-4.2.8p10]# make installcd ./html && \    ../scripts/build/checkHtmlFileDatescd . && \    ./scripts/build/checkChangeLogmake  install-recursivemake[1]: Entering directory `/usr/local/src/ntp-4.2.8p10'Making install in sntpmake[2]: Entering directory `/usr/local/src/ntp-4.2.8p10/sntp'[ ! -r ./../COPYRIGHT ]                 \    || [ check-COPYRIGHT-submake -nt ./../COPYRIGHT ]   \    || make  check-COPYRIGHT-submakemake  install-recursivemake[3]: Entering directory `/usr/local/src/ntp-4.2.8p10/sntp'Making ins
[root@localhost ntp-4.2.8p10]# cd /usr/local[root@localhost local]# lltotal 40drwxr-xr-x. 2 root root 4096 Sep 23  2011 bindrwxr-xr-x. 2 root root 4096 Sep 23  2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23  2011 gamesdrwxr-xr-x. 2 root root 4096 Sep 23  2011 includedrwxr-xr-x. 2 root root 4096 Sep 23  2011 libdrwxr-xr-x. 2 root root 4096 Sep 23  2011 libexecdrwxr-xr-x. 6 root root 4096 Apr 12 17:14 ntpdrwxr-xr-x. 2 root root 4096 Sep 23  2011 sbindrwxr-xr-x. 5 root root 4096 Apr 13  2017 sharedrwxr-xr-x. 3 root root 4096 Apr 12 17:09 src[root@localhost local]# cd ntp[root@localhost ntp]# lltotal 16drwxr-xr-x. 2 root root 4096 Apr 12 17:14 bindrwxr-xr-x. 2 root root 4096 Apr 12 17:14 libexecdrwxr-xr-x. 2 root root 4096 Apr 12 17:14 sbindrwxr-xr-x. 5 root root 4096 Apr 12 17:14 share[root@localhost ntp]# ll bintotal 6008-rwxr-xr-x. 1 root root    2844 Apr 12 17:14 calc_tickadj-rwxr-xr-x. 1 root root 2255174 Apr 12 17:14 ntpd-rwxr-xr-x. 1 root root  384466 Apr 12 17:14 ntpdate-rwxr-xr-x. 1 root root  791615 Apr 12 17:14 ntpdc-rwxr-xr-x. 1 root root  666160 Apr 12 17:14 ntp-keygen-rwxr-xr-x. 1 root root  832389 Apr 12 17:14 ntpq-rwxr-xr-x. 1 root root  198198 Apr 12 17:14 ntptime-rwxr-xr-x. 1 root root    3570 Apr 12 17:14 ntptrace-rwxr-xr-x. 1 root root    3210 Apr 12 17:14 ntp-wait-rwxr-xr-x. 1 root root  972854 Apr 12 17:14 sntp-rwxr-xr-x. 1 root root   11333 Apr 12 17:14 tickadj-rwxr-xr-x. 1 root root   11635 Apr 12 17:14 update-leap[root@localhost ntp]# ll share/doc/ man/ ntp/ [root@localhost ntp]# ll share/total 12drwxr-xr-x. 4 root root 4096 Apr 12 17:14 docdrwxr-xr-x. 5 root root 4096 Apr 12 17:14 mandrwxr-xr-x. 3 root root 4096 Apr 12 17:14 ntp[root@localhost ntp]# cd

上述执行时的输出贴了一堆,总结起来就是:

1.将源码解压在/usr/local/src目录下;

2.进入对应的目录,执行configure,注意prefix指定makefile中最后安装的目录,这个最后安装的目录通常是/usr/local/xxx,xxx是软件名;

3.执行make clean来先清除下“可能存在的.o文件”,实际上这一步一般不用也可以;

4.执行make编译源代码(注意,是编译,不是安装);

5.执行make install安装。

如果仅仅是安装到此为止就可以了,了解更多可以往下看看。

所谓的Tarball文件实际上是将源码先用tar打包,然后使用gzip或者bzip2压缩后得到的文件。

通常使用gzip压缩后得到的Tarball文件是:

xxx.tar.gz
xxx.tgz

通常使用bzip2压缩后得到的Tarball文件是:

xxx.tar.bz2

解压缩一个Tarball文件通常包含以下几项:

1.源代码文件;

2.configure/config检测程序;

3.自述文件README和安装说明INSTALL;

使用configure/config生成makefile然后即可安装。

注意:

make使用的是makefile或者Makefile,configure/config也是需要autoconfig这个软件来辅助的。

原本的Linux distribution发布安装的软件是在/usr中的,用户自行安装的软件建议放置在/usr/local下。

对于configure/config,如果没有显式地指明–prefix=/usr/local/xxx,那么默认将会是/usr/local。

对了,最后别忘记在/etc/man.config中加上刚装的软件的man路径。

0 0
原创粉丝点击