对于从Windows(Windows)切换到Linux的用户来说,最困难的调整之一是,并非您想要安装的所有软件都是现成的。与(在大多数情况下)将软件预先打包在EXE安装程序或ZIP文件中的Windows用户不同, (Windows)Linux用户通常必须编译自己的软件包。
如果你想知道如何在Linux(Linux)上编译软件包,你需要遵循几个步骤。您需要下载源代码,运行 configure 命令,安装任何所需的依赖包,然后运行 make 命令开始编译您的包。以下是如何在基于Linux的操作系统上完成所有这些操作。
下载源文件(Downloading Source Files)
在开始构建新软件包之前,您需要源代码。这可能来自您自己开发的包,在这种情况下,您应该已经可以访问源代码。
但是,您更有可能尝试在Linux上编译来自其他开发人员的软件包。流行的代码共享站点(如Github)允许您查看和下载(view and download the source code)包的源代码,然后您可以对其进行编译。您可以使用流行的版本控制系统GIT将源文件下载到您的 PC。
您也可以直接从VLC(VLC)等开源项目下载源代码。这些通常以压缩文件格式(compressed file format)出现,例如TAR.GZ,您可以使用tar命令在终端提取。例如,运行命令tar -xzvf source.tar.gz将提取一个名为source.tar.gz的 tarball 文件。
在您的Linux PC 上获得并提取源代码后,您可以在开始编译包之前进入下一个准备阶段。
在 Linux 上安装 Build-Essential(Installing Build-Essential On Linux)
无论源代码的编程语言如何,在Linux(Linux)操作系统上 编译的任何类型的软件都需要build-essential软件包中包含的工具和软件。
作为基本包,build-essential(或类似名称的包)应该在您的Linux发行版的软件存储库中可用。基于Arch (Arch) Linux的发行版上的 build-essential 等价物称为base-devel,其中包括许多相同的工具。
build-essential 的安装说明也会有所不同,具体取决于您的Linux发行版。例如,在基于Ubuntu和 Debian 的操作系统上,您可以通过打开终端窗口并键入sudo apt install build-essential 来安装 build-essential(sudo apt install build-essential)。
安装 build-essential 也会安装它的依赖项,比如g++包。此过程完成后,您可以在编译之前继续配置您的Linux源代码包。(Linux)
运行配置命令(Run The Configure Command)
主要包的源代码通常包含一个配置(configure)脚本。运行此脚本将检查您的Linux发行版是否有您的源代码需要能够正确编译的基本包。
要运行配置脚本,请使用cd(cd)命令输入提取的源代码的文件夹。从那里,在终端中输入./configure,按回车键运行它。
如果配置脚本检测到丢失的包,它会在脚本结束时通知您要做什么。例如,在编译VLC媒体播放器之前,上面运行的配置脚本检测到没有安装Lua编程语言。(Lua)
在某些情况下,即使配置脚本检测到缺少软件包或功能,您仍然可以编译和配置软件包。VLC的配置脚本(如上所示)通过建议您使用--disable-lua标志再次运行它来绕过它,为丢失的Lua编程语言包提供了解决方案。(Lua)
您需要安装配置脚本检测到的任何丢失的软件包或使用任何建议的禁用标志来绕过这些错误,然后才能继续。
如果配置脚本已完成且没有(或只有轻微)错误,则将为您的包创建配置的makefile 。这将创建编译包的说明,允许您进入最终的软件编译阶段。
安装缺少的依赖包(Install Missing Dependency Packages)
配置脚本有助于识别您的Linux发行版需要能够正确编译和安装新软件包的任何软件包。
这些可以通过您的配置脚本错误消息清楚地识别,或者通过运行该脚本的过程进一步回溯。如果错误消息没有说清楚,请向后滚动终端历史记录以尝试识别丢失的包裹。
一旦您知道缺少的软件包是什么,请使用Linux发行版的软件包安装程序来安装它。例如,在基于Ubuntu和 Debian 的操作系统上,运行sudo apt install package-name将安装一个包。
在开始编译和安装新软件包之前,安装任何缺少的依赖项是您需要完成的最后一个阶段。完成此过程后,您就可以开始编译了。
如何在 Linux 上编译(How to Compile on Linux)
build-essential包包含make ,这是一个自动工具,用于开始将源代码编译成可以在 PC 上运行的软件。它使用由前面的configure命令配置和创建的(configure)makefile文件,其中包含编译包所需的特定说明。
要开始编译源代码,请打开终端并使用cd命令输入正确的文件夹。准备好后,输入make开始编译你的包。
这将需要一些时间来完成,具体取决于包的大小和可用的系统资源。如果您的软件包编译后没有出现错误,您可以安装您的软件包。
为此,请在终端中键入sudo make install 。该软件包将安装在您的Linux PC 上,供您像任何其他软件一样打开和使用。
在 Linux 上安装新软件(Installing New Software On Linux)
了解如何在Linux(Linux)上编译软件包可以帮助您安装鲜为人知的软件。像Ubuntu(Ubuntu)和Devian这样的主要操作系统都有可供用户使用的大型软件存储库,因此如果您不想编译软件,请尝试使用包管理器查找和安装新软件。
如果您要从Windows迁移,您还可以在 Linux 上安装 Windows 软件,(install Windows software on Linux)以继续使用您最喜欢的仅限 Windows 的应用程序。
How To Compile Software Packages On Linux
One of the hardest adjustments for users who switch from Wіndows to Linux is the idea that not every bit of software you want to inѕtall is ready-made for you. Unlіke Windows users, who (in most cases) get software pre-packaged in an EXE installer or ZIP file, Lіnux users often have to compile their own softwarе packages.
If you want to know how to compile software packages on Linux, you’ll need to follow a few steps. You’ll need to download the source code, run the configure command, install any required dependency packages, then run the make command to begin compiling your package. Here’s how to do all of this on a Linux-based operating system.
Downloading Source Files
Before you begin building your new software packages, you need the source code. This could be from a package that you’ve developed yourself, in which case you should have access to the source code already.
It’s more likely, however, that you’re attempting to compile a software package on Linux from another developer. Popular code sharing sites like Github allow you to view and download the source code for packages, which you can then compile. You can use GIT, the popular version control system, to download the source files to your PC.
You can also download the source code from open-source projects like VLC directly. These usually come in a compressed file format like TAR.GZ, which you can extract at the terminal using the tar command. For instance, running the command tar -xzvf source.tar.gz would extract a tarball file named source.tar.gz.
Once you have the source code available and extracted on your Linux PC, you can move to the next stage of preparation before you begin compiling your package.
Installing Build-Essential On Linux
The tools and software contained in the build-essential package are required for any kind of software compiling on Linux operating systems, regardless of the programming language of your source code.
As an essential package, build-essential (or similarly named packages) should be available in the software repository for your Linux distribution. The equivalent of build-essential on Arch Linux-based distributions is called base-devel, which includes many of the same tools.
The installation instructions for build-essential will also vary, depending on your Linux distribution. For example, on Ubuntu and Debian-based operating systems, you can install build-essential by opening a terminal window and typing sudo apt install build-essential.
Installing build-essential will also install its dependencies, like the g++ package. Once this process is complete, you can move onto configuring your Linux source package before compiling it.
Run The Configure Command
The source code for major packages usually contains a configure script. Running this script will check your Linux distribution for the essential packages that your source code needs to be able to compile correctly.
To run the configure script, enter the folder for your extracted source code using the cd command. From there, type ./configure into the terminal, pressing enter to run it.
If the configure script detects a missing package, it will inform you of what to do at the end of the script. For example, before compiling the VLC media player, the configure script shown running above has detected that the Lua programming language is not installed.
In some cases, you can still compile and configure software packages, even if the configure script has detected a missing package or feature. The configure script for VLC (shown above) has offered a solution to the missing Lua programming language packages by suggesting you run it again with the –disable-lua flag to bypass it.
You’ll need to install any missing packages that the configure script has detected or use any suggested disable flags to bypass these errors before you can continue.
If the configure script has completed with no (or only minor) errors, the configured makefile for your package will be created. This creates the instructions to compile your package, allowing you to move to the final software compiling stage.
Install Missing Dependency Packages
The configure script helpfully identifies any packages that your Linux distribution requires to be able to compile and install your new software package correctly.
These may be clearly identified by your configure script error message or further back through the process of running that script. If the error message hasn’t made it clear, scroll back through your terminal history to try and identify the missing package.
Once you know what the missing package is, use the package installer for your Linux distribution to install it. For instance, on Ubuntu and Debian-based operating systems, running sudo apt install package-name will install a package.
Installing any missing dependencies is the final stage you need to complete before you can begin compiling and installing your new software package. Once you’ve completed this process, you’re ready to begin compiling.
How to Compile on Linux
The build-essential package contains make, the automatic tool used to begin compiling your source code into software that you can run on your PC. It uses the makefile file, configured and created by the earlier configure command, which contains the specific instructions needed to compile your package.
To begin compiling your source code, open a terminal and use the cd command to enter the correct folder. When you’re ready, type make to begin compiling your package.
This will take a little bit of time to complete, depending on the size of the package and your available system resources. If no errors appear after your software package has been compiled, you can then install your package.
To do this, type sudo make install in the terminal. The package will be installed on your Linux PC, ready for you to open and use like any other software.
Installing New Software On Linux
Knowing how to compile software packages on Linux can help you install less commonly-known software. Major operating systems like Ubuntu and Devian have large software repositories available to users, so if you don’t want to compile your software, try finding and installing new software using the package manager instead.
If you’re moving from Windows, you can also install Windows software on Linux to keep using your favorite Windows-only apps.