Compiling and installing software from source on Linux

Hua Weiyun 2022-06-23 18:17:52 阅读数:639

compilinginstallingsoftwaresourcelinux

although yumapt-getrpm It is very convenient to install the compiled software package , However, you may still encounter some situations where you must install software from source code .

This article explains how to compile and install software from source code at a very high level .

Download the source code package and unzip

Linux To compress the software source code on tar The form of the document appears , Usually has .tar.gz or .tar.bz2 Extension . Used to package source code into these tar The tools in the ball are “tar”( Used to merge multiple files into one )、“gzip” or bzip2( Used to compress ). To get the source code zip of a specific software , You need to know about the compressed package URL.

After getting the download link , Use “wget” Get... From the command line tarball.

$ wget <link to the tarball>

The above command will tarball Download to current directory .wget Commands are very flexible and have many options .

Next , You need to unzip tarball To access source code and other files . According to the extension , Use one of the following commands :

$ tar -xvfz <name of tarball with .tar.gz extension>(or)$ tar -xvfj <name of tarball with tar.bz2 extension>

Read the installation documentation

After downloading and extracting the software source code , The first thing to do is to read the documentation . This may sound boring to most of us , But this is a very important step , Because performing this step thoroughly will save you from most problems in the future . Documentation provides information about the software 、 Changes since the last version 、 Links to more documents 、 Information about the software author 、 Steps of compiling and installing software, etc . So we can see that there is a lot of valuable information in the document .

The whole information is roughly divided into two files :“Readme” and “Install”. although “ install ” It covers all the information required for compilation and installation , But all other information is contained in “ Readme ” In file . Please note that , The name and case of the file may vary .

To configure

After completing the above steps , We can assume that we have enough theoretical knowledge of the software , Now we can continue and configure the environment to compile and install the software on our system . Most packages come with a configuration script that can be used to configure the environment . The file name of the configuration file is mainly “ To configure ”. The script usually accepts parameters that can be used to control certain functions of the software . This script also ensures that all the tools necessary for compilation are present on the system .

To understand the options provided by a particular profile , Please run the following command :

$ configure --help

To start configuring the build environment , Please execute the following order :

$ ./configure

The above command will check and / Or create a build environment , If everything goes well , It will generate a file named “makefile” The file of . file “makefile” For software compilation .

assembly

Generate makefile after , Just run the following command in the same directory :

$ make

The above command will compile all the source code related to the software . If there is a problem with compilation , An error will be thrown on the console .

install

After successful compilation , All required binaries will be created . It is time to install these binaries in the standard path , So that they can be called from anywhere in the system . So , Please run the following command :

$ make install

Please note that , Sometimes installing software may require root jurisdiction , So you may get permission , Execute the above command, and then continue .

above 5 The three steps show how to get... From the source code 、 Unpack 、 To configure 、 Compile and install software . Besides , You can remove the decompression software tarball To do some cleanup .

When compiling and installing open source software from source code , There may be some problems / error . Let's take a look at some of the :

  • Missing shared library : Sometimes when you run the program you just installed , You will get one with some . Related errors , So that your program can't find . First ,.so Are we in Windows Of DLL A synonym for . These are the shared libraries required by the program . secondly , When your program is installed in some non-standard path or the shared library does not actually exist in your system , These types of errors will explode . For the first case , You need to tell shell Environment the installation path of these new shared libraries . This can be done by using “ldconfig” Command or modify LD_LIBRARY_PATH Variable to complete .
  • Corrupt source code : No matter how much pain you put into reading all the documentation and covering all the steps of building the software , But if there are some compilation errors in the source code , This means that the software has damaged the source code to a large extent . under these circumstances , In addition to feeding this problem back to the author of the software , incapable of action . meanwhile , If you think you can , You can debug errors and see if they are trivial errors that can be fixed ( Such as grammatical errors ).
  • No script configured : Although rare , But sometimes you will find that there is no configuration script in the source code directory . If this happens , That doesn't mean you're stuck . under these circumstances , You just need to read the documentation carefully , You will certainly find some information about the environment configuration for compiling and installing the software .
版权声明:本文为[Hua Weiyun]所创,转载请带上原文链接,感谢。 https://javamana.com/2022/174/202206231718256146.html