ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

时间:2024-04-11 20:48:34
ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

ubuntu 源码编译安装

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

Ubuntu and other Linux distributions have extensive package repositories to save you the trouble of compiling anything yourself. Still, sometimes you’ll find an obscure application or a new version of a program that you’ll have to compile from source.

Ubuntu和其他Linux发行版具有广泛的软件包存储库,可避免您自己编译任何内容的麻烦。 不过,有时候您会发现必须从源代码编译的晦涩的应用程序或程序的新版本。

You don’t have to be a programmer to build a program from source and install it on your system; you only have to know the basics. With just a few commands, you can build from source like a pro.

您不必是程序员就可以从源代码构建程序并将其安装在系统上。 您只需要了解基本知识。 仅需几个命令,您就可以像专业人士一样从源代码进行构建。

安装所需的软件 (Installing the Required Software)

Installing the build-essential package in Ubuntu’s package repositories automatically installs the basic software you’ll need to compile from source, like the GCC compiler and other utilities. Install it by running the following command in a terminal:

在Ubuntu软件包存储库中安装build-essential软件包会自动安装您需要从源代码编译的基本软件,例如GCC编译器和其他实用程序。 通过在终端中运行以下命令来安装它:

sudo apt-get install build-essential

sudo apt-get install build-essential

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

Type Y and press Enter to confirm installation when prompted.

键入Y并在出现提示时按Enter确认安装。

获取源码包 (Getting a Source Package)

Now you’ll need your desired application’s source code. These packages are usually in compressed files with the .tar.gz or .tar.bz2 file extensions.

现在,您需要所需的应用程序的源代码。 这些软件包通常位于带有.tar.gz或.tar.bz2文件扩展名的压缩文件中。

As an example, let’s try compiling Pidgin from source — maybe there’s a newer version that hasn’t been packaged yet and we want it now. Locate the program’s .tar.gz or .tar.bz2 file and save it to your computer.

举例来说,让我们尝试从源代码编译Pidgin-也许有一个尚未打包的较新版本,我们现在就需要。 找到该程序的.tar.gz或.tar.bz2文件并将其保存到您的计算机。

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

A .tar.gz or .tar.bz2 is like a .zip file. To use it, we’ll have to extract its contents.

.tar.gz或.tar.bz2类似于.zip文件。 要使用它,我们必须提取其内容。

Use this command to extract a .tar.gz file:

使用以下命令提取.tar.gz文件:

tar -xzvf file.tar.gz

tar -xzvf file.tar.gz

Or use this command to extract a .tar.bz2 file:

或使用以下命令提取.tar.bz2文件:

tar -xjvf file.tar.bz2

tar -xjvf file.tar.bz2

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

You’ll end up with a directory with the same name as your source code package. Use the cd command to enter it.

您将得到一个与源代码包同名的目录。 使用cd命令输入它。

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

解决依赖关系 (Resolving Dependencies)

Once you’re in the extracted directory, run the following command:

进入解压缩的目录后,运行以下命令:

./configure

。/配置

(Note that some applications may not use ./configure. Check the “README” or “INSTALL” file in the application’s extracted folder for more specific instructions.)

(请注意,某些应用程序可能不使用./configure。请查看应用程序提取文件夹中的“ README”或“ INSTALL”文件以获取更多具体说明。)

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

(The ./ part tells the Bash shell to look inside the current directory for the “configure” file and run it. If you omitted the ./, Bash would look for a program named “configure” in system directories like /bin and /usr/bin.)

(./部分告诉Bash shell在当前目录中查找“ configure”文件并运行它。如果省略了./,则Bash会在/ bin和/等系统目录中查找名为“ configure”的程序。 usr / bin。)

The ./configure command checks your system for the required software needed to build the program.

./configure命令检查系统中是否有构建程序所需的必需软件。

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

Unless you’re lucky (or already have a lot of required packages on your system), you’ll receive error messages, indicating you’ll need to install certain packages. Here, we see an error message saying the intltool scripts aren’t present on their system. We can install them with the following command:

除非您很幸运(或者您的系统上已经有很多必需的软件包),否则您会收到错误消息,表明您需要安装某些软件包。 在这里,我们看到一条错误消息,指出intltool脚本不在其系统上。 我们可以使用以下命令安装它们:

sudo apt-get install intltool

sudo apt-get install intltool

After installing the required software, run the ./configure command again. If you need to install additional software, repeat this process with the sudo apt-get install command until ./configure completes successfully. Not every required package will have the exact name you see in the error message — you may need to Google the error message to determine the required packages.

安装所需的软件后,再次运行./configure命令。 如果需要安装其他软件,请使用sudo apt-get install命令重复此过程,直到./configure成功完成。 并非每个必需的软件包都将具有您在错误消息中看到的确切名称-您可能需要Google错误消息来确定所需的软件包。

If an older version of the program you’re trying to compile is already in Ubuntu’s software repositories, you can cheat with the sudo apt-get build-dep command. For example, if I run sudo apt-get build-dep pidgin, apt-get will automatically download and install all the dependencies I’ll need to compile Pidgin. As you can see, many of the packages you’ll need end in -dev.

如果您要编译的较旧版本的程序已经存在于Ubuntu的软件存储库中,则可以使用sudo apt-get build-dep命令作弊。 例如,如果我运行sudo apt-get build-dep pidgin ,apt-get将自动下载并安装编译Pidgin所需的所有依赖项。 如您所见,您需要使用的许多软件包都以-dev结尾。

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

Once ./configure completes successfully, you’re ready to compile and install the package.

./configure成功完成后,就可以编译并安装软件包了。

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

编译安装 (Compiling and Installing)

Use the following command to compile the program:

使用以下命令来编译程序:

make

使

This process may take some time, depending on your system and the size of the program. If ./configure completed successfully, make shouldn’t have any problems. You’ll see the lines of text scroll by as the program compiles.

此过程可能需要一些时间,具体取决于您的系统和程序的大小。 如果./configure成功完成,则make应该没有任何问题。 您将在程序编译时看到文本行滚动。

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

After this command finishes, the program is successfully compiled — but it’s not installed. Use the following command to install it to your system:

此命令完成后,程序已成功编译-但尚未安装。 使用以下命令将其安装到系统中:

sudo make install

须藤使安装

It’ll probably be stored under /usr/local on your system. /usr/local/bin is part of your system’s path, which means we can just type “pidgin” into a terminal to launch Pidgin with no fuss.

它可能存储在系统上的/ usr / local下。 / usr / local / bin是系统路径的一部分,这意味着我们只需在终端中输入“ pidgin ”即可启动Pidgin,而不必大惊小怪。

ubuntu 源码编译安装_如何在Ubuntu上从源代码编译和安装

Don’t delete the program’s directory if you want to install it later — you can run the following command from the directory to uninstall the program from your system:

如果要稍后安装,请不要删除该程序的目录-您可以从该目录中运行以下命令以从系统中卸载该程序:

sudo make uninstall

sudo make卸载



Programs you install this way won’t be automatically updated by Ubuntu’s Update Manager, even if they contain security vulnerabilities. Unless you require a specific application or version that isn’t in Ubuntu’s software repositories, it’s a good idea to stick with your distribution’s official packages.

这样安装的程序即使包含安全漏洞也不会被Ubuntu的更新管理器自动更新。 除非您需要Ubuntu软件存储库中没有的特定应用程序或版本,否则最好坚持使用发行版的官方软件包。

There are a lot of advanced tricks we haven’t covered here — but, hopefully, the process of compiling your own Linux software isn’t as scary anymore.

我们这里没有涉及许多高级技巧,但是希望,编译自己Linux软件的过程不再那么令人恐惧。

翻译自: https://www.howtogeek.com/105413/how-to-compile-and-install-from-source-on-ubuntu/

ubuntu 源码编译安装