Linux Package Management source code compilation installation

Source: Internet
Author: User
Tags bz2

First, the Linux package basic concept

1.1. Linux program development follows open source agreement: GPL, BSE, Apache, etc.

1.2, the source program common development language: C, C + +, Perl, Python, etc.

1.3. Application development, compilation and operation

Just as the material used by the baker is flour rather than maizhong, most of our applications are not directly exposed to the hardware layer when developing the program, because the underlying hardware is too abstract and "ugly", and if application development starts from the bottom, there is no doubt that the workload is enormous. As a result, some system-level programmers on the "bare metal" put on a layer of operating system to manage hardware resources, the system software is closer to the user, like the maizhong into a grain of wheat. The operating system is still relatively abstract, so there are some library-level programmers in the operating system based on the development of some functions or classes can be directly used (known as library files), a further layer from the user, this stage is like grinding wheat into flour. As a result, our application programmers can directly invoke these library files for programming without having to care about the underlying work mechanism.


The ①API(Application Programming Interface, Application programming Interface) is the library (development Library, runtime) that the above mentioned program development and runtime relies on, the library is some good function module , It's like a "part" that can be used directly, but it has no entry, cannot be executed independently, and can only be executed when the program is called independently .

② application development relies on the header file (head)In addition to the function library. A header file is a link between an application and a library of functions, which is a declaration of a function library , such as telling us which functions to invoke, the types of arguments that the function can accept, and so on. In Linux, the header file suffix is. h, located in the /usr/include directory

After the ③ source program is written, the next step is to compile. Program compilation refers to a high-level language written in the source program, translated into the machine executable binary format file process , generally through preprocessing → compilation → assembly → link a few steps.

Compilation is also divided into static compilation and dynamic compilation:

static compilation : Refers to the compiler when compiling the program, the program needs to call the library functions extracted and included in the program, that is, "bring your own parts." The advantage of this method of compiling is that the portability is strong, the disadvantage is that the execution file size is large.

Dynamic compilation : In short, "without parts". The advantage is that the compilation speed is fast, the execution file size is small, the disadvantage is that if the corresponding runtime is not installed on other computers, the dynamically compiled executable cannot be run.

Abi(Application Binary interface, Application binary interface) is the binary interface supported by the system kernel, and the hardware platform determines the system-compatible ABI. Therefore, statically compiled executables on the x86 platform can run on various systems on the same hardware platform, but not on other hardware platforms such as Powpc,arm


Summary: Closer to hardware than Api,abi. APIs are about operating systems, and ABI is about hardware platforms. The application runs on both the ABI and the runtime . Compiled binary format files on Windows based on the X86 platform cannot run on ARM platform-based Linux because the ABI is different, even for Windows and Linux on the same hardware platform, Dynamically compiled executables on Windows are not necessarily able to run on Linux because the runtime may be different


1.4, the composition of the Linux program and package format:

①linux components after the installation of the program:

binaries:/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin,/usr/local/app/{bin,sbin}

Note: Some special applications are placed in the Libexec directory; some third-party apps are installed by default in the/OPT directory

Library files (development library, Runtime):/lib64,/usr/lib64,/usr/local/lib64,/usr/local/app/lib

ldd: Displays the shared library on which the program depends

Usage:ldd/path/to/binary_file, such as Ldd/bin/ls

configuration file :/etc,/usr/local/app/etc or conf directory

Help Files :/usr/share/man,/usr/local/share/man,/usr/local/app/man

[Email protected] ~]# ldd/bin/lslinux-vdso.so.1 = (0x00007fff45104000) libselinux.so.1 =/lib64/ Libselinux.so.1 (0x0000003463400000) librt.so.1 =/lib64/librt.so.1 (0x0000003462400000) # preceded by a library file name, Back for library file path libcap.so.2 =/lib64/libcap.so.2 (0x0000003465000000)

The packages on the ②linux are available in three formats: source package , binary format package,RPM format Package .


Ii. source code compilation and installation

Most applications are now installed using the RPM format package, which is easy to install and easy to manage, but because the RPM format package is a compiled package and sometimes does not meet the specific needs of the individual, some programs do not have the RPM format package, and therefore require source code compilation and installation

2.1, the source Package command format :name-version.tar.{ GZ,BZ2,XZ}, where version:major.minor.release, such as bash-4.2.3.tar.gz

2.2. Source of Open source applications

① Self-built site: such as APACHE,MYSQL,DRBD ...

② code hosting: such as sourceforge,github.com,code.google.com ...

2.3. Source Code Compilation Tool :

gcc(GNU C complier): Compiling C programs

Gcc-c++: Compiling C + + programs

2.4, the source Code organization format: The source code is organized in the form of multiple files, this is easy to modify and manage, not because of a code snippet changes to recompile the entire code. The code in each file is dependent

2.5.GNUmake: project management tool , which organizes code snippets scattered across files, automatically determines the order in which parts of the program are compiled, which parts need to be recompiled, and invokes a compilation tool (such as GCC) to perform the compilation operation.


2.6. Steps to compile and install the source program :

①tar Tar XF Testapp-version.tar. {Xz|bz2|gz}

②CD testapp-version

③./configure #configure脚本的作用一是检查编译环境, instead, configure the features you want to compile. It will combine with another file makefile.in generate the Makefile for the Make tool

④make #make工具会读取makefile并调用编译工具进行编译

⑤make Install #安装

Note: before compiling, make sure that the basic development environment is ready , and that the two development pack groups, Server Platform development and development tools, are required. In addition, program compilation may also depend on a specific development package, which can be installed as prompted


2.7. Use of Configure scripts

① Get help:./configure--help

② some of the more general options

Installation path Related:

--prefix=/path/to/somewhere #指定安装路径, if not specified, the program's parts of the file will be scattered in more than one directory, not easy to manage

--sysconfdir=/path/to/somewhere #指定配置文件安装路径

Specify which features are enabled/disabled:

--enable-feature, such as--ENABLE-FPM

--disable-feature, such as--disable-socket

Specify the features, programs, or files that you depend on:

--with-function[=/path/to/somewhere]

--without-function

Note: the options that can be configured for each program may vary, depending on the./configure--help


2.8, after the installation of the configuration

Program run:

① the input program name directly without entering its absolute path

Vim/etc/profile.d/appname.sh #将程序的二进制文件所在目录加入PATH环境变量中

Export path= $PATH:/path/to/somewhere

Export manual page

Edit the /etc/man.config file, add a manpath, and the path is the man directory for the new installer

or specify the path to the man manual search by option in the command: Man-m/path/to/somewhere KEYWORD

Program development: If other applications rely on the development environment of this program, or do two development for this program

The default search for library files located in the directories listed in/lib64,/usr/lib64 and configuration files/etc/ld.d.conf does not search the library files in the/usr/local/lib64 and/usr/local/appname/lib directories

Exporting library files

Step one: Specify a path for the system to search for customizations

Edit/etc/ld.so.conf.d/appname.conf, enter the library path

Second step: Use the Ldconfig command to trigger the system to re-search all library files and generate the cache, the cache file defaults to/etc/ld.so.cache

Export Header file

The path to the system read header file is:/usr/include

Suppose the program's header file path is:/usr/local/appname/include

How to export: Create a soft link

Ln-sv/usr/local/appname/include/usr/include/appname


2.9. Example: simple compile and install Nginx

[[email protected] ~]# yum grouplist | grep  ' Develop '   # See if the Basic Development Pack group is installed    Additional Development   Desktop Platform  development   development tools   server platform development[[ email protected] ~]# tar xf nginx-1.4.7.tar.gz   #解压源码包 [[email  protected] ~]# lsanaconda-ks.cfg  documents  install.log          Music        nginx-1.4.7.tar.gz   Public     VideosDesktop           Downloads  install.log.syslog  nginx-1.4.7  Pictures             Templates  vmware-tools-distrib[[email  protected] ~]# cd nginx-1.4.7[[Email protected] nginx-1.4.7]# lsauto  changes  changes.ru  conf   configure  contrib  html  license  man  readme   src[[email protected] nginx-1.4.7]# ./configure --help   #查看可配置的功能   --help                              print this  message  --prefix=path                       set installation prefix  --sbin-path =path                    set nginx binary pathname  --conf-path=PATH                    set nginx.conf pathname  -- Error-log-path=path              set  error log pathname  --pid-path=PATH                     set nginx.pid pathname  &NBSP, ..... [[email protected] nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --conf-path=/ Etc/nginx/nginx.confchecking for os + linux 2.6.32-431.el6.x86_64 x86_64checking  for C compiler ... not found./configure: error: C compiler  cc is not found   #提示无C程序编译器 [[email protected] nginx-1.4.7]# yum - y install gcc   #安装gcc ... complete! [[EMAIL&NBSP;PROTECTED]&NBSP;NGINX-1.4.7]#&NBSP;./CONFIGURE&NBSP;--PREfix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf..../configure: error: the http  rewrite module requires the PCRE library.   #提示需要pcre库You  can  either disable the module by using --without-http_rewrite_moduleoption,  or install the PCRE library into the system, or build  The pcre librarystatically from the source with nginx by using  --with-pcre=<path> option. [[email protected] nginx-1.4.7]# yum -y install pcre-devel   #安装pcre开发包 ... [[email protected] nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --conf-path=/ etc/nginx/nginx.conf..../configure: error: the http gzip module requires  the zlib library.   #提示需要zlib库 ... [[email protected] nginx-1.4.7]# yum -y install zlib-devel ... [[email protected] nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --conf-path=// Etc/nginx/nginx.conf ... [[email protected] nginx-1.4.7]# make   #调用编译工具执行编译 ... [[email protected] nginx-1.4.7]# make install   #安装 ... [[email protected] nginx-1.4.7]# cd /usr/local/nginx[[email protected] nginx]# &NBSP;LSHTML&NBSP;&NBSP;LOGS&NBSP;&NBSP;SBIN[[EMAIL&NBSP;PROTECTED]&NBSP;NGINX]#&NBSP;SBIN/NGINX&NBSP;&AMP;[1]  5455[[email protected] nginx]# ss -tnlp[[email protected] nginx]# vim  /etc/profile.d/nginx.shexport path= $PATH:/usr/local/nginx/sbin   #将该程序的二进制文件目录路径加入PATH变量 [[ email protected] nginx]# . /etc/profile.d/nginx.sh   #重读该配置文件 [[email  protected] nginx]# echo  $PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/ usr/sbin:/usr/bin:/root/bin:/usr/local/nginx/sbin# compiled and installed service program with no service script, additional 


Three or two use of the binary format package

The binary format package is a compiled package, so it can be used directly after decompression, similar to green software on Windows systems

3.1. command format for binary format packages :name-version-os-arch-.tar.{ GZ,BZ2,XZ}, where Version:major.minor.release,os is the applicable system for binary format packages, arch is the applicable hardware platform. such as mysql-5.5.42-linux2.6-x86_64.tar.gz

3.2, for ease of management, binary format package is generally extracted to the/usr/local directory

[[email protected] ~]# tar-xf mysql-5.5.33-linux2.6-x86_64.tar.gz-c/usr/local[[email protected] ~]# ls/usr/localbin E TC Games include Lib Lib64 libexec mysql-5.5.33-linux2.6-x86_64 sbin share src[[email protected] ~]# Mv/usr/loca l/mysql-5.5.33-linux2.6-x86_64//usr/local/mysql[[email protected] ~]# Cd/usr/local/mysql[[email protected] mysql]# Lsbin COPYING data docs include Install-binary lib man mysql-test README scripts share Sql-bench Support-file S ...


Linux Package Management source code compilation installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.