Home > System Tutorial > LINUX > body text

Binary packages vs source code packages under Linux: Which should you choose?

WBOY
Release: 2024-02-14 19:06:02
forward
921 people have browsed it

In Linux systems, the installation program is usually different from the traditional Windows installation software method. You can install it from a pre-built package or compile the program yourself. In those increasingly popular distributions, pre-built packages are often the primary solution. But sometimes, you may also need to compile from source code. This is also one of the characteristics of the Linux operating system. Compiling a program from source code ensures that the program will run properly on the system and allows for more flexibility and customization. No matter which method you choose, you need to choose the method that works best for you based on your needs.

What is a binary package?

Linux 下二进制包 vs 源代码包:你应该选择哪个?

Installing programs on Linux is usually different from the traditional way of installing software on Windows. Rather than downloading the installer from the vendor's website, the files come from a program repository, usually customized to your Linux distribution. You can access this repository using your Linux package manager or app store.

The programs in these repositories are composed of multiple files and packaged in an archive format for easy access and distribution. For example, Debian uses the DEB format to store and distribute programs. These packaged files are called binary packages.

How to read binary code

You need a special program to extract these files and install them on your computer, usually your package manager or app store. These tools also have other useful features, such as tracking installed files and managing software updates.

Newer package formats, such as Flatpak and Snap, work with different versions of Linux, but they still consist of precompiled binaries. Both require a graphical app store or a command line-based package manager for installation.

What is source code?

All software consists of lines of text called source code, written in a specific programming language, such as C or C++. Normally, you can't just package this source code into an archive file and call it a package. These lines need to be translated into a language that the computer can understand and execute.

This process is called compilation, and the end result is to create a binary file that the computer can run. The difference between a software package and software is that the binary files of software are stored in a package along with other files such as configuration files.

What is "install from source"?

Linux 下二进制包 vs 源代码包:你应该选择哪个?

Installing a program from source means installing without using a package manager. You need to compile the source code and copy the binaries to your computer.

In most cases, you can download the project's source code from a hosting service such as GitHub, GitLab, or Bitbucket. Larger programs may even host source code on a personal website. This code is usually compressed in an archive format (also called a source code package).

A special set of tools helps automate the build process. On the Linux desktop, it usually exists in the form of a command line program called make. Source code written in different languages ​​requires specific compilers and commands to convert it into binaries. The make program automates this process.

To make this automation work, the program provides a file called Makefile that tells make what it should do and how to compile it. Nowadays, Makefiles are usually automatically generated by special software such as CMake. This is where you need to step in. From here, you can specify the specific functionality you want compiled into the software.

Example built from source

For example, the following command uses CMake to generate a configuration file for the Calligra office suite. The file created tells the make program to compile only Calligra's Writer component.

cmake -DPRODUCTSET=WORDS -DCMAKE_INSTALL_PREFIX=$HOME/kde/inst5 $HOME/kde/src/calligra
Copy after login

After completing this step, users can simply run the make tool to compile and copy the results to their computer. The steps are as follows:

make
make install
Copy after login
Linux 下二进制包 vs 源代码包:你应该选择哪个?

Although this is the general mode for compiling a program, there are many other ways to install source code packages. For example, Gentoo Linux has a built-in way of handling source code packages, making the process faster and easier. But building a binary package requires more steps than the above command.

Benefits of using binary packages

If you use Linux, there is a good chance that someone has precompiled the software you have installed. This is more common than using source code packages. But why is this happening?

1. The binary version is easier to manage

Linux 下二进制包 vs 源代码包:你应该选择哪个?

Binary packages not only contain compiled installation files, but also store other information, making it easy for your package manager to keep track of all your programs. For example, DEB files (the package format for Debian and its derivatives) also contain important information such as other software required for the program to run and its current version.

This makes installing the package much simpler because you don't need to worry about what other files are needed to successfully run the program. Your package manager can read this information from the package itself and download all necessary dependencies automatically.

And when installing a program from source code, unless the code is compiled into a stand-alone binary package, you will be responsible for managing the software. You need to remember what other programs you need to make it work and install them yourself.

2. The binary version has better stability

People responsible for maintaining package manager repositories often test binaries and try to fix problems that arise. This may result in improved stability, as package maintainers may discover problems that may have been overlooked by those installing the source code.

Additionally, packages usually must adhere to a strict set of rules to ensure they will run on your system. For example, Debian and Ubuntu both have a policy manual, and many other Linux distributions have similar manuals.

Some programs also rely on different versions of the same software dependencies to run. The package repository will try its best to resolve these conflicts to avoid causing trouble for you.

Benefits of compiling source code packages

Installing a program from source is not something everyone needs to do, as it is usually easier to maintain your computer if you stick to binary packages. Still, there are some advantages to using this slightly more complicated way of installing a program.

1. Source code provides the latest software

One drawback to making a program more reliable is that it takes time to improve and fix. Sometimes there may be binaries available, but the source code will be provided later. For those who want to have the latest and greatest software, they may be willing to sacrifice a little stability while exchanging for newer software.

Although there are some Linux operating systems that can meet this need without compiling the program, they also have some disadvantages. For example, software that does not release fixed package versions frequently will have difficulty keeping up to date in the repository. In contrast, installing from source does not have these restrictions.

This is because binary packages are usually made based on officially released program versions. Therefore, changes between these versions are usually not taken into account. By compiling your own software from source code, you can benefit from these changes immediately.

It is also possible that your Linux operating system does not prepare the software you want for you in advance. In the past, this would have made installing from source the only option. Common package formats have changed this. Flatpak and Snap packages also generally receive updates faster than system repositories. But there are still times when compilation is the only way to get the software you want.

2. You can choose the function yourself

Linux 下二进制包 vs 源代码包:你应该选择哪个?

Function of FFmpeg Another benefit of using source code packages is that you have more control over the programs you install. When installing from a binary repository, you are limited in your ability to customize packages.

Take FFmpeg as an example, it is a command line-based audio and video conversion tool. By default, it comes with a ton of features, some of which you may never use. For example, FFmpeg supports JACK audio, although this software is typically only used in production environments.

By compiling FFmpeg, you can remove features you don't need and make it more lightweight and fit your needs. The same principle applies to other huge programs.

When resources are limited, removing functions can effectively reduce the load. It's no wonder that Gentoo Linux-based ChromeOS is used on many low-end computers. Gentoo is based on source code and compiles many software, potentially making these systems lighter to run.

Why not use both binary and source packages?

While you may not want to compile packages every day, this is a useful approach. Still, with the new universal package format available from sites like the Snap Store and Flathub, you're less likely to need to build from source to get the latest software.

The above is the detailed content of Binary packages vs source code packages under Linux: Which should you choose?. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template