Source code package installation of Linux software installation method

Before the advent of package manager technology (such as RPM packages, Deb packages), a program installation method was usually adopted.

1. Download and unzip the source package file.

Linux source packages are usually compressed and archived in formats such as gzip or bzip2, so they also have the suffixes of .tar.gz and .tar.bz2. If you want to use the source package to install, you need to decompress and switch to the source code. The directory where the package is located.
Here is cmake as an example (cmake is a commonly used compilation tool in Linux systems).
Switch to the directory that needs to be downloaded

[root@hollowman~]# cd /usr/local/src/

Download cmake source package

[root@hollowman src]# wget https://www.linuxprobe.com/Software/cmake-2.8.11.2.tar.gz

Use the tar command to decompress the source package.
If the xzvf parameter is used, a cmake-2.8.11.2directory will be generated in the current directory and the source file will be decompressed to that directory.

[root@hollowman src]# tar xzvf cmake-2.8.11.2.tar.gz

Switch to the directory where the source file is located, the commands in the subsequent steps will be completed in this directory

[root@hollowman src]# cd cmake-2.8.11.2/

2. Generate source code package and compile code (configure)

After executing the decompression, an executable script program named configure is generated. It is used to check whether the system has the required libraries during compilation, and whether the version of the library meets the needs of compilation and other system information required for installation. If the check passes, a MakeFile file for compilation will be generated. The function of the prefix parameter is to specify the installation directory of the source package program, so as to locate the installation program more accurately and ensure that the software is more controllable.

[root@hollowman cmake-2.8.11.2]# ./configure --prefix=/usr/local/program

Just like the role of configure, if a problem is found, an error message will be displayed. The following means that cmake lacks the C language compilation environment (gcc and gcc-c++), which needs to be installed first.

---------------------------------------------
CMake 2.8.11.2, Copyright 2000-2012 Kitware, Inc.
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C compiler on this system.
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /usr/local/src/cmake-2.8.11.2/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------

Install C language compilation environment (yum tool is used here)

[root@hollowman cmake-2.8.11.2]# yum install gcc gcc-c++

Compile the cmake source code package again, execute it normally and generate the compiled code and Makefile file

[root@hollowman cmake-2.8.11.2]# ./configure --prefix=/usr/local/program

3. Compile and generate binary installer (make)

The Makefile file generated after the configure command is executed will save the relevant dependencies and installation rules required during the source code compilation process, so you can directly compile and generate the binary installation file customized for the current system through the make command.

[root@hollowman cmake-2.8.11.2]# make

4. Run the binary installation file (make install)

At this point, the source package already contains the installation rules and binary installation files required for the package installation, and you only need to execute the installation through the make install command. If the prefix parameter is used in the first step of compiling, the program will be installed to the specified directory, otherwise it is generally installed in the /usr/local/bin directory by default. However, this is not absolute. Generally, the install or readme file in the installation directory will have relevant instructions.

[root@hollowman cmake-2.8.11.2]# make install

5. Clean up temporary files of source package (make clean)

The source code installation process will generate some temporary junk files. In order to save disk space, the temporary files in the source code package can be cleaned up by the make clean command.

[root@hollowman cmake-2.8.11.2]# make clean

Guess you like

Origin blog.csdn.net/ymz641/article/details/111472909