Basic Linux Tutorial: Install software from source code

Source: Internet
Author: User

Basic Linux Tutorial: Install software from source code
Why install software from source code?

Under what circumstances do we need to install software from the source code? I think it is similar to these situations: one case is that the software releases a new version, and the release version is not followed up in a timely manner. At this time, if you want to taste it, you have to rely on yourself; another scenario is that no binary package can be directly used by software developers or existing systems, and you have to use the software yourself; of course, there are other situations. All in all, learning to install software from source code is a very important skill.

What is make and configure?

Make is a program. When you execute make, make searches for the makefile text file in the current directory. Makefile defines how the source code is compiled in detail, how to call gcc to compile the source code to generate the target file, and how to link to generate executable files.

How is makefile generated? Generally, software developers provide a detection program to detect the user's operating system environment. After the program is detected, the makefile will be automatically created.

Preparations

So how can we install software from the source code? First, you must prepare the source code for compilation. This includes two aspects:

  1. Compilation tools: To compile source code into executable binary files, compilation tools are essential: gcc, g ++, make, autoconfig, and so on. In the CentOS series, you can install yum-y groupinstall "Development Tools. In Ubuntu, You can executesudo apt-get install build-essentialCommand to install the basic compilation tool. Depending on the actual situation of the compiled program, you may also need to install other tools.

  2. Compile dependencies: In addition to installing basic compilation tools, we also need to install the dependencies required by the program in order to compile the source code smoothly. Contains the library functions provided by the system and the dependent packages of third-party software. In the CentOS series, you can install the corresponding dependency package through yum-y install xxxx-devel. The Ubuntu system can usesudo apt-get build-depThe command is followed by the package name to prepare the required dependencies. In general, if configure or make reports an error, the error information clearly indicates that the dependency is missing. Or copy the error information to google to solve the problem.

 

Source code installation 3 environment:./configure; make & make install

Before compiling the source code, you must download the software source code package to your hard disk. Generally, program source code packages are often packaged into the .tar.gz and .tar.bz2 formats. The former is available.tar zxvf *.tar.gzTo unpack the package. The latter usestar jxvf *.tar.bz2. We recommend that you extract the package to the/usr/local/src directory: # tar xf * .tar.gz-C/usr/local/src

Generally, after unpacking, we should read the relevant instruction files attached to the program, such as README (self-report file) and INSTALL (Installation File), to learn about program compilation. This step is very important !!!

When everything is ready, let's perform the source code compilation trilogy.

  1. Configure and create the makefile file: This is the first step to compile the source code../configureCommand complete. Execute this step to prepare for source code compilation. Common options are:--Prefix = PREFIX, used to specify the installation location of the program. You can use -- help to query more options. Some programs do not need to perform this step.

  2. Compile: Once the configuration is passed, you can use it immediately.makeCommand according to the definition of makefile, call gcc to execute the source code compilation process. Depending on the specific circumstances of the software, the time required for compilation varies. What we need to do is to wait patiently and stay calm. Although this step only contains simple instructions, the problems encountered sometimes are very complicated. The most common case is that the program compilation fails to be completed successfully. In this case, you need to analyze the error prompt to find the corresponding solution. You need to execute make clean and then re-execute the make command.

  3. Installation: If the compilation is normal, executemake installYou can install the program in the system.

Note that the above steps must be performed step by step. As long as one of the steps fails, there is no way to proceed in the future.

 

Management: Directory planning, uninstallation, and upgrade
  • The source code is usually decompressed to the/usr/local/src directory.

  • It is best to install it in the/usr/local directory during installation.

  • Add the man page of the software to man path, edit/etc/man. config, and add MANPATH items.

  • Add the bin directory of the software to the PATH environment variable, edit/etc/profile. d/xxxx. sh, and add export PATH = $ PATH:/usr/local/xxx/bin.

What should I do if I think the compiled software is not suitable enough and want to delete it? We only need to go to the directory where the source code is compiled and runsudo make uninstallCommand.

Related reading: C ++ static library and dynamic library

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

Related Article

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.