Compile and install programs through source code in Linux

Source: Internet
Author: User

Compile and install programs through source code in Linux

This article briefly records how to install programs through the source code in Linux and related knowledge. (Do not spray ^_^)

I. Components of the program

In Linux, most programs are composed of the following parts:

Binary File: A program file that can be run

Library files: files under the lib directory that we usually see

Configuration File: Needless to say, we all know

Help document: This document is usually used to view commands using man commands in Linux.

Ii. Directory for storing programs in Linux

The directory for storing Linux programs is roughly three places:

/Etc,/bin,/sbin,/lib

/Usr/bin,/usr/sbin,/usr/lib: core features of the operating system, which can be partitioned separately

/Usr/local/bin,/usr/local/sbin,/usr/local/lib,/usr/local/etc,/usr/local/man: this is used to install third-party programs, which correspond to the directories of binary files, library files, configuration files, and help files.

Generally, the installation program is installed in the/usr/local directory.

3. Compile and install the source program

1. Run the following command to check whether the gcc compiler is installed. You cannot install gcc with yum.

Gcc -- version # Check whether gcc is installed

2. decompress the source code package, for example:

Tar-xvf nginx-1.7.7.tar.gz # extract source package

3. Enter the decompressed source code package:

Cd nginx-1.7.7 # enter the source package

4. Execute the configure file. This file has two functions: 1. Let the user select the compilation feature; 2. Check the compiling environment. After configure is executed, a MakeFile file is generated. For example:

./Configure -- prefix =/usr/local/nginx -- conf-path =/etc/nginx. conf

The installation path is determined through -- prefix, and the specific location of the configuration file is determined through -- conf-path. Note: not all programs have the same configure parameters./configure -- help can be used to view detailed parameter descriptions. If the library on which the program depends is not installed in the current system, configure reports an error. In this case, you must first install the dependent library.

5. Execute the make command to compile the program

Make

6. After the compilation is successful, you can install it. Execute the following command:

Make install

Even if the installation of this program is complete, do not forget that there will be subsequent configuration.

Iv. configuration procedure

1. Modify the PATH environment variable to identify the binary file PATH of the program;

Modify the/etc/profile file and add

Export PATH = $ PATH:/path/to/somewhere # Remember the directory where the executable file is located. do not include the executable file in the PATH.

Then execute:

Source/etc/profile # Our changes take effect

2. By default, the system searches for the path/lib,/usr/lib of the library file, and adds additional search paths (NOTE: Some programs do not provide library files, this setting is not required)

In/etc/ld. so. conf. d. conf is the file with the suffix, and then write the path to be added directly to this file; then execute the following command to make it take effect

Ldconfig

3. If the program provides a library file, the header file will also be provided. Generally, In the include directory of the installation directory, the path of the system's default scan header file is/usr/include. We can connect to the header file of our installer with a link under/usr/include.

Ln-s/usr/local/nginx/include/usr/include/yourname

4. The program may also provide help documentation, which is generally the man directory under the installation directory. To view the help documentation of our program using the man command, we need: in/etc/man. add a MANPATH in config to point to our document directory

This article permanently updates the link address:

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.