码迷,mamicode.com
首页 > 系统相关 > 详细

Linux—-软件安装

时间:2018-04-17 11:45:34      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:源代码   home   关联性   pps   ted   检验   imp   only   完整   

一、开放源码、编译程序、可执行文件

1Linux系统上真正识别的可执行文件是二进制文件。

2Shell script

shell script并不是可执行文件,shell script 只是利用shell这个程序的功能进行一些判断式,而最终执行的除了bash提供的功能外,仍是调用一些已经编译好的二进制程序来执行的。

3linux上如何判断一个文件是否为二进制文件

使用file命令

例如:file /etc/init.d/syslog

如果是二进制程序而且是可执行的时候,他就会显示可执行文件类(ELF 32-bit LSBexecutable),同时会说明是否使用共享库(shared libs),而如果是一般的script,那他就会显示出text executables之类的字样。

4二进制程序是如何来的呢?

linux 上面最标准的程序语言c语言,我们在书写完c语言代码之后,需要用gcc来对c语言进行编译,这样就可以制作一个可以执行的二进制程序。事实上,在编译的过程中还会生成“目标文件”这些文件是以*.0的扩展名形式存在的。至于c语言的源代码文件通常以.*c

作为扩展名。此外,有的时候,我们会在程序当中引用、调用其他的外部子程序,或者是利用其他软件提供的“函数功能”,这个时候我们就必须要在编译的过程当中将该函数库加进去,如此一来,编译程序就可以将所有的程序代码与函数库做一个链接(Link)以生成正确的执行文件。

总之,我们可以这么说:

开放源码:就是程序代码,写给人类看的程序语言,但机器并不认识,所以无法执行;

编译程序:将程序代码转译成为机器看得懂的语言,就类似翻译者的角色;

可执行文件:经过编译程序变成二进制程序后机器看得懂所以可以执行的文件。

 

5如何安装与升级软件

更新与升级软件可以分为两大类

1直接以源码通过编译来安装与升级

2直接以编译好的二进制程序来安装升级

上述第一点很简单,就是直接以Tarball在自己的机器上面进行检测、编译、安装与设置等操作来升级就是了。这样的操作虽然让用户在安装过程中具有很高的可选择性,但毕竟毕竟麻烦一点,如果linux distribution厂商能够针对自己的操作平台先进行编译等过程,在将编译好的二进制程序释放出的话,那由于我们的系统与该linux distribution的环境是相同的,所以它所释放出的二进制程序就可以在我们的机器上面直接安装,省略了监测与编译的复制过程。

这个预先编译好程序的机制存在于很多distribution,包括red hat系统开发的rpm管理机制与yum在线更新模式。

由于centos系统是依循标准的linux distribution ,所以可以使用tarball 直接进行编译安装与升级。在此先对tarball进行介绍。

一个软件的tarball是如何安装的呢?

流程如下:

1 tarball 由厂商的网页下载下来

2 tarball解压缩,生成很多的源码文件

3 开始以gcc进行源码的编译(会生成目标文件)

4然后以gcc进行函数库、主程序、子程序的链接,以形成主要的二进制文件。

5将上述的二进制文件以及相关的配置文件安装升级至自己的主机上面。

上面的第34步骤当中,我们可以通过make这个命令的功能来简化它,所以整个步骤其实是很简单的。只不过你就得需要至少有gcc以及make这两软件在你的linux系统里面才行。

二、tarball安装的基本步骤

1文字描述

  1取得原文件:将tarball文件在/usr/local/src目录下解压缩;

2取得步骤流程:进入新建立的目录下面,去查阅installreadme等相关文件内容。

3 相关属性软件安装:根据install/readme的内容查看并安装好一些相关的软件

4建立Makefile:以自动检测程序(configureconfig)检测操作环境,并建立makefile这个文件。

5编译:以make这个程序并使用该目录下的Makefile作为他的参数配置文件,来进行make的操作。

6安装:以make这个程序,并以Makefile这个参数配置文件,依据install这个目标的指定来安装到正确路径。

 

2命令化简

  1. ./configure  

  这个步骤就是建立Makefile这个文件,通常程序开发者会写一个script来检查你的linux 系统、相关的软件属性等,这个步骤相当重要,因为将来你的案子信息都是这一步骤内完成的。另外这个步骤的相关信息应该参考一下该目录的readmeinstall相关的文件。

  1. Makeclean

 Make会读取Makefile中关于clean的工作。这个步骤不一定会有,但是希望执行一下,因为它可以去除目标文件。

  1. Make

Make会依据Makefile当中的默认工作进行编译的行为。编译的工作主要是进行gcc来将源码编译成为可以被执行的目标文件,但是这些目标文件通常还需要一些函数库之类的链接后,才能生成一个完整的可执行文件!使用make就是要将源码编译成为可以被执行的可执行文件,而这个可执行文件会放置在目录前所在的目录之下,尚未被安装到预定安装的目录中。

4make install通常这就是最后的安装步骤了,make会依据Makefile这个文件里面关于install的选项,将上一个步骤所编译完成的数据安装到默认的目录中,就完成安装。

3注意

上面的步骤是一步一步来进行,而其中只要一个步骤无法成功,那么后续的步骤就完全没有办法进行的!因此,要确定每一步都是成功的才可以。比如,万一今天你在./confiure就不成功了,那么就表示Makefile无法被建立起来,要知道,后面的步骤都是根据Makefile来进行的,既然无法建立Makefile,后续的步骤当然无法成功。

如果在make无法成功的话,那就表示源文件无法被编译成可执行文件,那么make install 主要是将编译完成的文件放置到文件系统中的,既然没有可用的执行文件了,怎么进行安装呢,所以,要每一个步骤都正确无误才能往下继续做。

 

三、一般tarball软件安装的建议事项(如何删除、升级)

·1 tarball 要在/usr/local/src 里面解压缩

是因为在默认情况下,原本的linux distribution发布安装的软件大多是在/usr里面的,而用户自行安装的软件则建议放置在/usr/local里面,这是考虑到管理用户所安装软件的便利性。

所以:通常建议将自己安装的软件放置在/usr/local下面,而源码(Tarball)则建议放置在/usr/local/src下面。

·2 tarball软件安装的建议事项

1最后将tarball的原始数据解压缩到/usr/local/src

2安装时,最好安装到/usr/local这个默认路径下

3考虑将来反安装的步骤,最好可以将每个软件单独安装在/usr/local下面

4为安装到单独目录的软件的man page 加入man path搜索

 

四、安装ntp中了解下英文

 

1.install

 

Basic Installation

==================

 

   These are generic *nix installation instructions.

 

   For Windows/NT, please see ports/winnt and html/build/hints/winnt.html.

 

   The `configure‘ shell script attempts to guess correct values for

various system-dependent variables used during compilation(编译).  It uses

those values to create a `Makefile‘ in each directory of the package.

It may also create one or more `.h‘ files containing system-dependent(依赖)

Definitions(定义).  Finally, it creates a shell script `config.status‘ that

you can run in the future(日后) to recreate the current configuration, a file

`config.cache‘ that saves the results of its tests to speed up

reconfiguring, and a file `config.log‘ containing compiler(汇编) output

(useful mainly for debugging `configure‘).

 

   If you need to do unusual things to compile the package, please try

to figure(估算) out how `configure‘ could check whether to do them, and mail

diffs or instructions to the address given in the `README‘ so they can

be considered for(被认为是) the next release.  If at some point `config.cache‘

contains results you don‘t want to keep, you may remove or edit it.

 

   The file `configure.in‘ is used to create `configure‘ by a program

called `autoconf‘.  You only need `configure.in‘ if you want to change

it or regenerate `configure‘ using a newer version of `autoconf‘.

 

The simplest way to compile(汇编、编制) this package is:

 

  1. `cd‘ to the directory containing the package‘s source code and type

     `./configure‘ to configure the package for your system.  If you‘re

     using `csh‘ on an old version of System V, you might need to type

     `sh ./configure‘ instead to prevent `csh‘ from trying to execute(执行)

     `configure‘ itself.

 

     Running `configure‘ takes a while.  While running, it prints some

     messages telling which features(特征) it is checking for.

 

  2. Type `make‘ to compile the package.

 

  3. Optionally, type `make check‘ to run any self-tests that come with

     the package.

 

  4. Type `make install‘ to install the programs and any data files and

     Documentation(记录).

 

  5. You can remove the program binaries and object files from the

     source code directory by typing `make clean‘.  To also remove the

     files that `configure‘ created (so you can compile the package for

     a different kind of computer), type `make distclean‘.  There is

     also a `make maintainer-clean‘ target, but that is intended mainly

     for the package‘s developers.  If you use it, you may have to get

     all sorts of other programs in order to regenerate(回收) files that came

     with the distribution(分配).

 

Compilers and Options

=====================

 

   Some systems require unusual options for compilation or linking that

the `configure‘ script does not know about.  You can give `configure‘

initial values(初始值) for variables by setting them in the environment.  Using

a Bourne-compatible shell, you can do that on the command line like

this:

     CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure

 

Or on systems that have the `env‘ program, you can do it like this:

     env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure

 

Compiling For Multiple Architectures

====================================

 

   You can compile the package for more than one kind of computer at the

same time, by placing the object files for each architecture in their

own directory.  To do this, you must use a version of `make‘ that

supports the `VPATH‘ variable, such as GNU `make‘.  `cd‘ to the

directory where you want the object files and executables(可执行的) to go and run

the `configure‘ script.  `configure‘ automatically checks for the

source code in the directory that `configure‘ is in and in `..‘.

 

   If you have to use a `make‘ that does not supports the `VPATH‘

variable, you have to compile the package for one architecture at a time

in the source code directory.  After you have installed the package for

one architecture, use `make distclean‘ before reconfiguring(重新配置) for another

architecture.

 

Installation Names

==================

 

   By default(默认情况下), `make install‘ will install the package‘s files in

`/usr/local/bin‘, `/usr/local/man‘, etc.  You can specify(指定) an

installation prefix other than `/usr/local‘ by giving `configure‘ the

option `--prefix=PATH‘.

 

   You can specify(指定) separate(分开) installation prefixes(前缀) for

architecture-specific files and architecture-independent files.  If you

give `configure‘ the option `--exec-prefix=PATH‘, the package will use

PATH as the prefix for installing programs and libraries.

Documentation and other data files will still use the regular prefix.

 

   If the package supports it, you can cause programs to be installed

with an extra prefix or suffix(后缀) on their names by giving `configure‘ the

option `--program-prefix=PREFIX‘ or `--program-suffix=SUFFIX‘.

 

Optional Features

=================

 

   Some packages pay attention to `--enable-FEATURE‘ options to

`configure‘, where FEATURE indicates(指示) an optional part of the package.

They may also pay attention to `--with-PACKAGE‘ options, where PACKAGE

is something like `gnu-as‘ or `x‘ (for the X Window System).  The

`README‘ should mention any `--enable-‘ and `--with-‘ options that the

package recognizes.

 

   For packages that use the X Window System, `configure‘ can usually

find the X include and library files automatically(自动的), but if it doesn‘t,

you can use the `configure‘ options `--x-includes=DIR‘ and

`--x-libraries=DIR‘ to specify their locations.

 

Specifying(指定) the System Type

   There may be some features(特色) `configure‘ can not figure out

automatically, but needs to determine(决定) by the type of host the package

will run on.  Usually `configure‘ can figure that out, but if it prints

a message saying it can not guess the host type, give it the

`--host=TYPE‘ option.  TYPE can either be a short name for the system

type, such as `sun4‘, or a canonical name with three fields:

     CPU-COMPANY-SYSTEM

 

See the file `config.sub‘ for the possible values of each field.  If

`config.sub‘ isn‘t included in this package, then this package doesn‘t

need to know the host type.

 

   If you are building compiler tools for cross-compiling, you can also

use the `--target=TYPE‘ option to select the type of system they will

produce code for and the `--build=TYPE‘ option to select the type of

system on which you are compiling the package.

 

Sharing Defaults

================

 

   If you want to set default values for `configure‘ scripts to share,

you can create a site shell script called `config.site‘ that gives

default values for variables like `CC‘, `cache_file‘, and `prefix‘.

`configure‘ looks for `PREFIX/share/config.site‘ if it exists, then

`PREFIX/etc/config.site‘ if it exists.  Or, you can set the

`CONFIG_SITE‘ environment variable to the location of the site script.

A warning: not all `configure‘ scripts look for a site script.

 

Operation Controls

==================

 

   `configure‘ recognizes(确认承认) the following options to control how it

operates.

 

`--cache-file=FILE‘

     Use and save the results of the tests in FILE instead of

     `./config.cache‘.  Set FILE to `/dev/null‘ to disable caching, for

     debugging `configure‘.

 

`--help‘

     Print a summary of the options to `configure‘, and exit.

 

`--quiet‘

`--silent‘

`-q‘

     Do not print messages saying which checks are being made.

 

`--srcdir=DIR‘

     Look for the package‘s source code in directory DIR.  Usually

     `configure‘ can determine that directory automatically.

 

`--version‘

     Print the version of Autoconf used to generate the `configure‘

     script, and exit.

 

`configure‘ also accepts some other, not widely useful, options.

 

2configure 支持参数

`configure‘ configures ntp 4.2.4p7 to adapt(适应于) to many kinds of systems.

 

Usage: ./configure [OPTION]... [VAR=VALUE]...

 

To assign(分派) environment variables (e.g., CC, CFLAGS...), specify(详细说明) them as

VAR=VALUE.  See below for(下面的) descriptions of some of the useful variables.

 

Defaults for the options are specified (指定的)in brackets(在括号内).

 

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

  -q, --quiet, --silent   do not print `checking...‘ messages

      --cache-file=FILE   cache test results in FILE [disabled]

  -C, --config-cache      alias for(别名) `--cache-file=config.cache‘

  -n, --no-create         do not create output(产出) files

      --srcdir=DIR        find the sources(来源) in DIR [configure dir or `..‘]

 

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‘.

 

For better control, use the options below.

 

Fine tuning of(微调) the installation directories:

  --bindir=DIR           user executables [EPREFIX/bin]

  --sbindir=DIR          system admin executables(可执行的) [EPREFIX/sbin]

  --libexecdir=DIR       program executables [EPREFIX/libexec]

  --datadir=DIR          read-only architecture-independent data [PREFIX/share]

  --sysconfdir=DIR       read-only single-machine data [PREFIX/etc]

  --sharedstatedir=DIR   modifiable(可更改的) architecture-independent data [PREFIX/com]

  --localstatedir=DIR    modifiable single-machine data [PREFIX/var]

  --libdir=DIR           object code libraries [EPREFIX/lib]

  --includedir=DIR       C header files [PREFIX/include]

  --oldincludedir=DIR    C header files for non-gcc [/usr/include]

  --infodir=DIR          info documentation [PREFIX/info]

  --mandir=DIR           man documentation [PREFIX/man]

 

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]

 

Optional Features:

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

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

  --disable-dependency-tracking  speeds up one-time build

  --enable-dependency-tracking   do not reject slow dependency extractors

  --enable-shared[=PKGS]

                          build shared libraries [default=no]

  --enable-local-libopts  Force using the supplied libopts tearoff code

  --disable-libopts-install

                          Do not install libopts with client installation

  --disable-optional-args not wanting optional option args

  --enable-static[=PKGS]

                          build static libraries [default=yes]

  --enable-fast-install[=PKGS]

                          optimize for fast installation [default=yes]

  --disable-libtool-lock  avoid locking (might break parallel builds)

  --enable-getifaddrs     s Enable the use of getifaddrs() [yes|no|glibc].

                          glibc: Use getifaddrs() in glibc if you know it

                          supports IPv6.

  --enable-debugging      + include debugging code

  --enable-debug-timing   - include processing time debugging code (costs

                          performance)

  --enable-dst-minutes    n minutes per DST adjustment [60]

  --enable-ignore-dns-errors

                          - retry DNS queries on any error

  --enable-BANCOMM        - Datum/Bancomm bc635/VME interface

  --enable-GPSVME         - TrueTime GPS receiver/VME interface

  --enable-all-clocks     + include all suitable non-PARSE clocks:

  --enable-ACTS           s ACTS modem service

  --enable-ARBITER        + Arbiter 1088A/B GPS receiver

  --enable-ARCRON-MSF     + Arcron MSF receiver

  --enable-AS2201         + Austron 2200A/2201A GPS receiver

  --enable-ATOM           s ATOM PPS interface

  --enable-CHRONOLOG      + Chrono-log K-series WWVB receiver

  --enable-CHU            + CHU modem/decoder

  --enable-AUDIO-CHU      s CHU audio/decoder

  --enable-DATUM          s Datum Programmable Time System

  --enable-DUMBCLOCK      + Dumb generic hh:mm:ss local clock

  --enable-FG             + Forum Graphic GPS

  --enable-HEATH          s Heath GC-1000 WWV/WWVH receiver

  --enable-HOPFSERIAL     + hopf serial clock device

  --enable-HOPFPCI        + hopf 6039 PCI board

  --enable-HPGPS          + HP 58503A GPS receiver

  --enable-IRIG           s IRIG audio decoder

  --enable-JJY            + JJY receiver

  --enable-JUPITER        s Rockwell Jupiter GPS receiver

  --enable-LEITCH         + Leitch CSD 5300 Master Clock System Driver

  --enable-LOCAL-CLOCK    + local clock reference

  --enable-MX4200         s Magnavox MX4200 GPS receiver

  --enable-NEOCLOCK4X     + NeoClock4X DCF77 / TDF receiver

  --enable-NMEA           + NMEA GPS receiver

  --enable-ONCORE         s Motorola VP/UT Oncore GPS receiver

  --enable-PALISADE       s Palisade clock

  --enable-PCF            + Conrad parallel port radio clock

  --enable-PST            + PST/Traconex 1020 WWV/WWVH receiver

  --enable-RIPENCC        - RIPENCC specific Trimble driver

  --enable-SHM            s SHM clock attached thru shared memory

  --enable-SPECTRACOM     + Spectracom 8170/Netclock/2 WWVB receiver

  --enable-TPRO           s KSI/Odetics TPRO/S GPS receiver/IRIG interface

  --enable-TRUETIME       s Kinemetrics/TrueTime receivers

  --enable-TT560          - TrueTime 560 IRIG-B decoder

  --enable-ULINK          + Ultralink WWVB receiver

  --enable-WWV            s WWV Audio receiver

  --enable-ZYFER          + Zyfer GPStarplus receiver

  --enable-parse-clocks   - include all suitable PARSE clocks:

  --enable-COMPUTIME      s Diem Computime Radio Clock

  --enable-DCF7000        s ELV/DCF7000 clock

  --enable-HOPF6021       s HOPF 6021 clock

  --enable-MEINBERG       s Meinberg clocks

  --enable-RAWDCF         s DCF77 raw time code

  --enable-RCC8000        s RCC 8000 clock

  --enable-SCHMID         s Schmid DCF77 clock

  --enable-TRIMTAIP       s Trimble GPS receiver/TAIP protocol

  --enable-TRIMTSIP       s Trimble GPS receiver/TSIP protocol

  --enable-WHARTON        s WHARTON 400A Series clock

  --enable-VARITEXT       s VARITEXT clock

  --enable-kmem           s read /dev/kmem for tick and/or tickadj

  --enable-accurate-adjtime

                          s the adjtime() call is accurate

  --enable-tick=VALUE     s force a value for ‘tick‘

  --enable-tickadj=VALUE  s force a value for ‘tickadj‘

  --enable-simulator      - build/install the NTPD simulator?

  --enable-slew-always    s always slew the time

  --enable-step-slew      s step and slew the time

  --enable-ntpdate-step   s if ntpdate should step the time

  --enable-hourly-todr-sync

                          s if we should sync TODR hourly

  --enable-kernel-fll-bug s if we should avoid a kernel FLL bug

  --enable-irig-sawtooth  s if we should enable the IRIG sawtooth filter

  --enable-nist           - if we should enable the NIST lockclock scheme

  --enable-ntp-signd      - Provide support for Samba‘s signing daemon,

                          =/var/run/ntp_signd

  --enable-wintime        - Provide the windows symmetric client hack

  --enable-clockctl       s Use /dev/clockctl for non-root clock control

  --enable-linuxcaps      + Use Linux capabilities for non-root clock control

  --enable-ipv6           s use IPv6?

 

Optional Packages:

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

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

  --with-autoopts-config  specify the config-info script

  --with-regex-header     a reg expr header is specified

  --with-libregex         libregex installation prefix

  --with-libregex-cflags  libregex compile flags

  --with-libregex-libs    libregex link command arguments

  --with-binsubdir        bin ={bin,sbin}

  --with-arlib            - Compile the async resolver library?

  --without-rpath         s Disable auto-added -R linker paths

  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]

  --with-pic              try to use only PIC/non-PIC objects [default=use

                          both]

  --with-tags[=TAGS]

                          include additional configurations [automatic]

  --with-openssl-libdir   + =/something/reasonable

  --with-openssl-incdir   + =/something/reasonable

  --with-crypto           + =openssl

  --with-electricfence    - compile with ElectricFence malloc debugger

  --with-kame             - =/usr/local/v6

 

Some influential environment variables:

  CC          C compiler command

  CFLAGS      C compiler flags

  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a

              nonstandard directory <lib dir>

  CPPFLAGS    C/C++ preprocessor flags, e.g. -I<include dir> if you have

              headers in a nonstandard directory <include dir>

  CPP         C preprocessor

 

Use these variables to override(覆盖) the choices made by `configure‘ or to help

it to find libraries and programs with nonstandard(不标准的) names/locations.

五、利用patch 更新源码

六、RPM

1Rpm的优点:

RPM内含已经编译过的程序与设置文件等数据,可以让用户免除重新编译的困