您的位置:首页 > 运维架构 > Linux

Linux源码编译安装

2016-02-04 14:02 447 查看


源码在Github或The
Linux KernelArchives上都以一个tarball档案的方式发布。tarball是压缩过的tar(tape
archive)档案。源码tarball名称通常有版本资讯(如linux-2.6.32.tar.gz中的linux-2.6.32),副档名为.tar.gz或.tgz(如linux-2.6.32.tar.gz中的.tar.gz)。
tarball套件安装的基本步骤如下:

步骤
说明
<1>下载tarball
 
<2>将tarball解打包压缩
通常解包到/usr/local/src/tarballname的目录下,包含:

<1>源码档案

<2>源码检测档案(可能是configure或config等档名)

<3>本套件的简易说明与安装说明(INSTALL或README)
<3>安装依赖套件
比如要编译源文件,则需要gcc套件
<4>执行configure
检测工作环境,并生成Makefile档案
<5>执行make
将源码编译成可执行文件,并放置在当前的目录下
<6>执行make install
将当前目录下的可执行文件安装到预定安装的目录中
默认情况下,Linuxdistribution发布安装的软件大多是在/usr里面的,而用户自行安装的软件则建议放置在/usr/local里面,源码(tarball)则建议放置在/usr/local/src下面。

以gcc来说明linuxdistribution的默认安装路径:

root@ubuntu:~# find / -name gcc

/etc/bash_completion.d/gcc                /*gcc命令自动补全功能*/

/usr/bin/gcc                                            
/*可执行文件*/

/usr/lib/gcc                                              
/*函数库*/

/usr/share/man/man1/gcc-4.4.1.gz   /*gcc在线帮助文档*/

/usr/share/doc/gcc-4.4-base/gcc       
/*gcc文件说明*/

root@ubuntu:~#
如果将自行安装的软件放置在/usr/local里面,则由于/usr/local原本就默认了这几个目录,所以数据就会被放在:

/usr/local/bin

/usr/local/lib

/usr/local/man
自行安装时,默认路径就是/usr/local,但将来想要升级或删除时需要追查文件源并一一删除,这样会比较麻烦。所以一般建议将安装路径设为/usr/local/tarballname。当需要卸载时,直接rm
-rf /usr/local/tarballname即可。

/usr/local/tarballname/bin

/usr/local/tarballname/lib

/usr/local/tarballname/man
当然,需要设置命令的路径。因为在执行某些命令时,与该命令是否在PATH这个环境变量所记录的路径有关,如果不想以绝对路径执行(/usr/local/tarballname/bin),需要在PATH里加入/usr/local/tarballname/bin。另外,/usr/local/tarballname/man也需要加入man
page的搜索路径当中/etc/manpath.config。

root@ubuntu:/usr/local# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
步骤解析:

【1】
tarball的解打包压缩


*.tar.gz 使用命令:tar zxvf *.tar.gz

*.tar.bz2使用命令:tar jxvf*.tar.bz2

【2】执行./configure

configure的参数可通过--help来查看:

root@ubuntu:/usr/local/src/fuse-2.8.4# ./configure --help



Configuration:

 -h, --help             display
this help and exit

     --help=short       display
options specific to this package

     --help=recursive   display
the short help of all the included packages

 -V, --version          display
version information and exit

 …

Installation directories:   /*指定软件安装路径*/

 --prefix=PREFIX        install
architecture-independent files in PREFIX

                         [/usr/local]

 --exec-prefix=EPREFIX  install
architecture-dependent files in EPREFIX

                         [PREFIX]

By default, `make install' will install all the files in

`/usr/local/bin', `/usr/local/lib' etc. You can specify

an installation prefix other than `/usr/local' using `--prefix',

for instance `--prefix=$HOME'.

  …

Program names:

 --program-prefix=PREFIX           prepend
PREFIX to installed program names

 --program-suffix=SUFFIX           append
SUFFIX to installed program names

 --program-transform-name=PROGRAM  run
sed PROGRAM on installed program names

 

System types:

 --build=BUILD    configure
for building on BUILD [guessed]

 --host=HOST      cross-compile
to build programs to run on HOST [BUILD]

 --target=TARGET  configure
for building compilers for TARGET [HOST]

 

Optional Features:

 --disable-option-checking ignore
unrecognized --enable/--with options

 --disable-FEATURE      do
not include FEATURE (same as --enable-FEATURE=no)

 --enable-FEATURE[=ARG] include
FEATURE [ARG=yes]

 --enable-shared[=PKGS] build
shared libraries [default=yes]

  …

Optional Packages:

 --with-PACKAGE[=ARG]   use
PACKAGE [ARG=yes]

 --without-PACKAGE      do
not use PACKAGE (same as --with-PACKAGE=no)

  …

Some influential environment variables:

 CC         C
compiler command

 CFLAGS     C
compiler flags

 …
【3】执行make

make的参数可通过help来查看:

root@ubuntu: /usr/local/src/fuse-2.8.4#make --help

Usage: make [options] [target] ...

Options:

 -b, -m                     Ignored
for compatibility.

 -B, --always-make          Unconditionally
make all targets.

 -h, --help                 Print
this message and exit.

 -i, --ignore-errors        Ignore
errors from commands.

 -j
, --jobs[=N]
         Allow N jobs at once; infinite jobs with no arg.

 -k, --keep-going           Keep
going when some targets can't be made.

 …
【4】执行make
install
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息