Package manager and apt

1. What is a package

A "package" (or "software package") usually refers to an application, which can be a GUI application, a command line tool, or a software library (required by other software programs). A package is essentially an archive file that contains binary executable files, configuration files, and sometimes dependency information.

In the old days, software used to be installed from its source code. You will refer to a file (usually named README) to see what software components it needs and the location of the binary files. It usually includes a configuration script or Makefile. You have to compile the software yourself or handle all the dependencies yourself (some software requires other software to be installed).

In order to get rid of this complexity, the Linux distribution has created its own packaging format to provide end users with ready-to-use binary files (pre-compiled software) to install the software, while providing some metadata (version number, description) and dependencies .

It's like baking a cake and buying a cake.
Around the mid-1990s, Debian created the DEB packaging format (.deb), and Red Hat Linux created the RPM (abbreviation for Red Hat Package Manager) packaging system (.rpm). The way to compile the source code still exists, but it is now optional.
Insert picture description here
To interact with or use the packaging system, you need a package manager. Users only need to decide what cake to eat, and how to do it is a store-like software warehouse.

2. How does the package manager work?

Remember, the package manager is a general concept, it is not unique to Linux. You will often find package managers for various software or programming languages. There are PIP package managers for Python packages only. Even the Atom editor has its own package manager. Since the focus of this article is Linux, I will start from the perspective of Linux. However, most of the explanations here can also be applied to general package managers. I created this diagram (based on SUSE Wiki) so that you can easily understand how the package manager works.
Insert picture description here
Almost all Linux distributions have a " software repository ", which is basically a collection of software packages. Yes, there can be more than one software library. The software library contains different kinds of software packages.

The software warehouse also has a metadata file, which contains information about the software package, such as the name of the software package, the version number, the description of the software package, and the software warehouse name. This is what you see using the apt show command in Ubuntu/Debian.

The package manager on your system will first interact with the metadata. The package manager creates a local cache of metadata on your system. When you run the update option of the package manager (such as apt update), it will update the local metadata cache by referencing the metadata in the repository.

When you run the installation command of the package manager (for example, apt install package_name), the package manager will reference this cache. If it finds the package information in the cache, it will use the Internet to connect to the corresponding warehouse and download the package before installing it on your system.

A package may have dependencies. This means that it may need to install other software packages. The package manager usually handles these dependencies and automatically installs them along with the package you are installing.

Insert picture description here
The package manager in Linux handles dependencies : Similarly, when you use the package manager to delete a package, it will either automatically delete it or notify you that the system has unused packages that can be cleaned up.

In addition to installing and deleting these obvious tasks, you can also use the package manager to configure the package and manage it according to your needs. For example, you can prevent the version of a package from being upgraded during regular system updates. Your package manager may be able to do a lot more.

Different types of package managers The
Insert picture description here
package managers vary depending on the packaging system, but the same packaging system may have multiple package managers. The package manager is not necessarily based on the command line, there are also graphical package management tools, such as Synaptic. The "Software Center" of your distribution is also a package manager, even if it is running apt-get or DNF underneath. For example, RPM has Yum and DNF package managers. For DEB, you have command-line-based package managers such as apt-get and aptitude.

Three, Ubuntu's apt tool

Advanced Packaging Tools (English: Advanced Packaging Tools, abbreviated as APT) is Debian and its derivative Linux package manager. Using this tool, we can easily download, configure and install software formats in binary or source code format. For Debian systems, the dpkg tool is often talked about. This function is similar to the apt function.

apt provides an advanced command line interface for the package management system. If you are a relatively early user of Ubuntu, you may often use apt-get instead of apt. Compared to apt-get, apt is more like a simplified version of apt-get. The simplification is reflected in only mentioning the most common commands. And options. After all, not everyone likes lengthy control commands. Take a look at the comparison between apt and apt-get:

apt command apt-get command meaning
apt install apt-get install Install a package
apt remove apt-get remove Uninstall a package
apt purge apt-get purge Uninstall and remove configuration files
apt update apt-get update Update repository index
apt upgrade apt-get upgrade Upgrade all upgradeable packages
apt autoremove apt-get auto remove Automatically delete unnecessary packages
apt full-upgrade apt-get dist-upgrade Automatically handle dependencies when upgrading packages
apt search apt-get search Search application
apt show apt-cache show Show installation package details

Take cmake as an example to see how to use this tool.

Uninstall cmake : sudo apt remove cmake
Insert picture description here
install cmake : sudo apt install cmake
Insert picture description here
cmake application information view :
Insert picture description here
From the information displayed by the apt manager, you can see:

  • cmake version is3.16.3
  • size
  • rely
  • Homepage
  • description
  • APT-source location: http://mirrors.aliyun.com/ubuntu focal/main amd64 Packages

The specific location may be a bit different from APT-source: http://mirrors.aliyun.com/ubuntu/dists/focal/main/binary-amd64/Packages.gz, in this compressed package, we can see cmake Related configuration:

Package: cmake
Architecture: amd64
Version: 3.16.3-1ubuntu1
Multi-Arch: foreign
Priority: optional
Section: devel
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Debian CMake Team <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 18758
Depends: cmake-data (= 3.16.3-1ubuntu1), procps, libarchive13 (>= 3.3.3), libc6 (>= 2.17), libcurl4 (>= 7.16.2), libexpat1 (>= 2.0.1), libgcc-s1 (>= 3.0), libjsoncpp1 (>= 1.7.4), librhash0 (>= 1.2.6), libstdc++6 (>= 9), libuv1 (>= 1.11.0), zlib1g (>= 1:1.1.4)
Recommends: gcc, make
Suggests: cmake-doc, ninja-build
Filename: pool/main/c/cmake/cmake_3.16.3-1ubuntu1_amd64.deb
Size: 3668668
MD5sum: 0901cd90df683245c1c63aa25494e895
SHA1: 987da0bb67fef6ed1cc4bdf791c983534dea4341
SHA256: 1f09f5bd58627092ed1787538051ce9f5f016ab279fe4c795e01faa1f9619180
Homepage: https://cmake.org/
Description: cross-platform, open-source make system
Description-md5: 47b53839da906127970f1e8c870afc2d

To put it simply, given an address, whenever the Ubuntu authentication is passed, the new installation package will be updated to the package on the website, and the user can synchronize the address of the new software through the upgrade. So is there a way to install a higher version of cmake?

  • ppa
  • Binary code
  • Source code

Four, Ubuntu software warehouse management tools

A software warehouse is a set of files that contains information about various software and its versions, as well as other detailed information such as checksums. Each version of Ubuntu has its own four official software repositories :

  • Main-Free and open source software supported by Canonical;
  • Universe-free and open source software maintained by the community;
  • Restricted-the proprietary driver of the device;
  • Multiverse-software restricted by copyright or legal issues.
    Insert picture description here
    In addition to the official software, there are other software (Other Software) , the most common may be VSCODE!
    Insert picture description here

The system retrieves the corresponding information through /etc/aptthe sources.listfiles stored in the directory , which can help the system obtain the corresponding software package from the website where the software is actually stored. In this case, when you run the sudo apt updatecommand, your system will use the APT tool to check the software repository and store the software and its version information in the cache. When you use the sudo apt install package_namecommand, it gets the package from the URL of the actual storage software through the information. If there is no information about a certain package in the software warehouse, it will prompt E:Unable to locate package. There is a problem with using the official repository: In order to ensure compatibility, the new tools developed and updated in Ubuntu will not be updated to the existing system immediately, but will be officially added to the official repository after some tests. This time may be several months. . So how can we solve it? Through PPA!

PPA

PPA (Personal Package Archive) is a warehouse that contains software information when a personal package is archived. The personal meaning is exclusive to the developer and does not have a formal license for distribution. Ubuntu provides a platform called Launchpad that enables software developers to create their own software repositories. End-user, that is, you can add the PPA repository to sources.list file when you update the system, your system will know the availability of this new software, then you can use the standard sudo apt installcommand to install it.

  • sudo add-apt-repository <PPA_info>This command adds the PPA repository to the list.
  • sudo apt-get update This command updates the list of packages that can be installed on the current system.
  • sudo apt-get install <package_in_PPA> This command installs the package.

Such as:

sudo add-apt-repository ppa:dr-akulavich/lighttable

You will notice that this command does not have the URL of the software repository. This is because the tool is designed to abstract the URL information before showing it to you.

A little note: if you add ppa:dr-akulavich/lighttable, you will get the Light Table. But if you add ppa:dr-akulavich, you will get all the repositories or packages in the "upper software repository". It is divided by level.

Basically, when you add a PPA using add-apt-repository, it will perform the same operations as manually running these commands:

deb http://ppa.launchpad.net/dr-akulavich/lighttable/ubuntu YOUR_UBUNTU_VERSION_HERE main
deb-src http://ppa.launchpad.net/dr-akulavich/lighttable/ubuntu YOUR_UBUNTU_VERSION_HERE main

The above two lines are the traditional way to add any software repository to your system's sources.list file. But PPA will automatically complete these tasks for you, without considering the exact software warehouse URL and operating system version.

The less important point here is that when you use PPA, it does not change the original sources.list file. On the contrary, it /etc/apt/sources.dcreates two files in the system-level directory, a .list and backup files with a .save suffix.
Insert picture description here
This is a security measure to ensure that the added PPA will not be confused with the original sources.list file. It also helps to remove the PPA.
You may ask why you want to use PPA, PPA needs to be used through the command line, not everyone likes to use the command line. Why not directly distribute DEB packages that can be installed graphically?

The answer lies in the update process. If you use the DEB package to install software, there is no guarantee that the installed software will be updated to a newer version when you run the sudo apt update and sudo apt upgrade commands.

This is because the apt upgrade process relies on the sources.list file. If there is no corresponding software entry in the file, it will not be updated through the standard software update procedure.

So does this mean that the software installed with DEB will never be updated? no. It depends on how the DEB package was created.

Some developers will automatically add an entry to sources.list so that the software can be updated like normal software. Google Chrome browser is one such example.

Some software will notify you when a new version is available when it runs. You must download the new DEB package and run it again to update the current software to a newer version. Oracle Virtual Box is one such example.

For the remaining DEB packages, you have to manually find updates, which is very inconvenient, especially when your software is for Beta testers, you need to add many updates frequently. This is exactly the problem PPA is trying to solve.

[1] [APT] https://zh.wikipedia.org/wiki/APT
[2] [The difference between rpm and deb] https://www.cnblogs.com/longchang/p/12530697.html
[3] [ Linux (3): Linux package management tools] https://blog.csdn.net/xu_fengyu/article/details/85218057

Guess you like

Origin blog.csdn.net/weixin_39258979/article/details/111772857