tar.gz源代码包安装
As a systems administrator I generally use package managers to install software. But in some situations I can not use package manager because provided software version is old or do not compatible. In this situations how can I install new software from source code by compiling.
作为系统管理员,我通常使用程序包管理器来安装软件。 但是在某些情况下,由于提供的软件版本过旧或不兼容,所以我无法使用软件包管理器。 在这种情况下,如何通过编译从源代码安装新软件。
Software source code can be get in different forms like compressed files like tar.bz2
, tar.gz
or from repositories like git
, svn
etc. We will follow compressed way in this tutorial. To get more information about git
read following tutorial.
软件源代码可以采用不同形式,如tar.bz2
, tar.gz
等压缩文件,也可以从git
, svn
等存储库中获取。我们将在本教程中按照压缩方式进行操作。 要获取有关git
更多信息,请阅读以下教程。
用wget下载源代码(Download Source Code with wget)
As stated previously we will get source code with the tool named wget
.We will provide the url of the compressed source code. To get more information about wget look following tutorial.
如前所述,我们将使用名为wget
的工具获取源代码。我们将提供压缩源代码的url。 要获取有关wget的更多信息,请查看以下教程。
Wget Command Tutorial With Examples For Linux
$ wget http://poftut.com/HelloWorld.tar.gz
用tar提取源代码 (Extract Source Code with tar)
Downloaded source code is compressed with tar.gz
we will extract it with tar
command like below.
下载的源代码已用tar.gz
压缩,我们将使用tar
命令将其提取,如下所示。
$ tar xvf HelloWorld.tar.gz
安装编译器和必需的库 (Install Compiler and Required Libraries)
Before compiling the source code we need to install related compilers and required libraries. More information about the required libraries can be found in the README file of the source code. In this step we will install gcc
.
在编译源代码之前,我们需要安装相关的编译器和所需的库。 有关所需库的更多信息,可以在源代码的README文件中找到。 在这一步中,我们将安装gcc
。
$ sudo apt install gcc libgcc-5-dev
配置 (Configure)
Professional projects generally have configure
script. configure
script is used to te setup related files and folders before compiling. configure
gets information about the current system and compiler with libraries and created Makefile
.
专业项目通常具有configure
脚本。 configure
脚本用于在编译之前设置相关文件和文件夹。 configure
通过库和创建的Makefile
获取有关当前系统和编译器的信息。
$ ./configure
用make编译 (Compile with Make)
Now the most important part we will compile the source code. Make
is very useful tool to compile the source code according to provided configuration. there is very complex compile configurations where they are easily handled by make
command. We will just issue make
like below. make
should be run in source code root directory.
现在,最重要的部分我们将编译源代码。 Make
是非常有用的工具,可以根据提供的配置来编译源代码。 有非常复杂的编译配置,可以通过make
命令轻松地make
配置。 我们将如下发出make
。 make
应该在源代码的根目录中运行。
$ make
使编译更快 (Make Compile Faster)
Modern computers have more than single CPU core. If we do not provide any option the make
command will compile the source code only using single core. We can use other cores during compile with -j
option. This will use given number of cores. In this example we want to use 4 cores.
现代计算机具有多个CPU内核。 如果我们不提供任何选项, make
命令将仅使用单核编译源代码。 在使用-j
选项进行编译时,我们可以使用其他内核。 这将使用给定数量的内核。 在此示例中,我们要使用4个内核。
$ make -j 4
使用Make Install进行安装 (Install with Make Install)
Last step is installing the compiled binaries. We will use make install
command. If the binaries will be copied to the directories those we do not have write right we should use with sudo
command.
最后一步是安装编译的二进制文件。 我们将使用make install
命令。 如果将二进制文件复制到我们没有写权限的目录,则应与sudo
命令一起使用。
$ sudo make install
翻译自: https://www.poftut.com/install-tar-gz-tar-bz2-application-source-code/
tar.gz源代码包安装