Ubuntu Server Chapter 3 Package Management

When we talk about Linux, the meaning is different. It is generally believed that Linux refers to the Linux kernel, and the Linux kernel is an intermediate layer where the hardware system provides an interface to applications. Essentially, the Linux kernel is also an application. This application is geared towards hardware and other applications. In the operating system, we often come across a word, "library file", there are library files ending with ".so" under Linux, and library files ending with ".dll" under Windows. The existence of library files is to facilitate developers to develop applications. Invoke hardware resources to the lower layer and provide a friendly development interface to the upper layer, so that the development and application can be reduced in complexity and functions can also be realized.

So what is the relationship between a Linux distribution and the Linux kernel?

The Linux distribution is an operating system that combines the kernel, library files, command line shell, graphical interface, and other application software packages to form a distribution.

Libraries and drivers must be dependent on other applications. If dependencies are missing or destroyed or modified, applications cannot run. Some layers of this dependency form a huge tree-like dependency structure. In order to manage this dependency, the concept of package management is introduced.

In addition to software installation, deletion, update, and configuration modification, package management also needs to provide other software dependencies (package management provides a set of its own stable dependencies).

The dependencies between different releases are different. It is recommended to use the package management tool officially provided by the release to avoid conflicts in dependencies. The package management also saves storage space, so that the same dependency is installed only once (avoid duplication of wheels).

Why are there not so many dependency problems under Windows? When I actually encounter dll missing in my daily use, I usually find the official dll to solve it. Windows is issued and maintained by Microsoft, but there are too many releases of Linux.

0 x01 package##

Common Linx software formats include RPM (Redhat) and DEB (Ubuntu inherited from Debian Linux). In the previous chapter 2, we talked about the release of packaged and compressed source codes such as Tar and Gzip. This kind of packaging is just a collection of multiple files. It does not have the function of file execution. RPM and DEB format files usually contain the following three contents:

In order to maintain the software package, all packages of the official package are placed in the official repository (Repositories), and the official provides a closed but quality-guaranteed package source. For example, a fruit company is also the same. As users, we need to use third-party software repositories carefully.

0 x02 Package Management Tool##

Dpkg local package manager###

Dpkg installs, deletes, and creates Deb packages locally. Note that I mean local, which means it does not rely on software repositories, does not automatically retrieve and download software packages, and cannot even solve the aforementioned dependencies.

dpkg -l #View local packages
dpkg -L package name#List all files installed locally by the package
dpkg -r package name#Uninstall package
dpkg -P package name#Delete the configuration file while uninstalling the software package
dpkg --print-architecture #Check the current architecture, the common ones are 64 (AMD64) and 32 (I386)
dpkg --print-foreign-architectures #View other supported architectures
This information comes from"/var/lib/dpkg/arch ", Which means that you can actually modify the displayed information.
dpkg --remove-architecture#Delete schema

0 x03 APT Package Manager###

The APT package manager is an official package management tool provided by Ubuntu. Like the Dpkg above, it can install, uninstall, update and even all the software packages of the entire operating system. During the installation process, it can automatically solve the dependency problem and update the software package based on the index. . The workflow of APT package manager consists of two parts,

apt update #Update index, add non-root"sudo"
vim /etc/apt/sources.list #If you want to increase the speed, it is recommended to use a well-known mirror source in China, and annotate the official source to modify the content of this file.
ls /etc/apt/sources.list.d #Generally store third-party source files
apt list --upgradable #View packages that can be updated
apt upgrade #Download and install the software package according to the index, and automatically resolve dependencies
apt dist-upgrade #The above command does not add or delete new packages, but this command will update new packages and delete old packages (including the kernel)
apt instll package name#Install package
apt remove package name--purge /apt purge package name#Delete the package and its configuration file
/var/log/dpkg.log #Contains the log of the installation or dpkg command to clear the package
apt search "name" #Search package by keyword
apt show name #Show package information
apt autoremove #Automatically delete packages that are no longer needed(When updating the kernel, using this command will delete the old kernel, which may cause dependency problems)
ls /var/cache/apt/archives #Location of downloaded deb package
ls /var/lib/apt/ #This directory holds the index file updated from the update source
apt download package name#Download the source code of the package
apt sorece sign up#Download the Deb file and source code and other files of the software package
apt showsec package name#Show package information

0 x04 automatic update##

As an enterprise system administrator or server administrator, when you need to manage a large number of servers, unattended is a good way to improve work efficiency.

What we need to do is install unattended installation packages and modify configuration files.

apt install unattended-upgrades
lsb_release -a  #View the current system version and Codename,Not enough permissions"sudo"/etc/apt/apt.conf.d/50unattended-upgrades #unattended-Upgrades configuration file (updated content), in the environment of enterprise generation, generally choose to update only security updates instead of general updates and scalability updates.
/etc/apt/apt.conf.d/10periodic #Time configuration file for updating index, downloading software package, automatic cleaning software package, and automatic installation, in days
service unattended-upgrades restart #The application in Ubuntu is basically this routine, install, modify the configuration file, restart the service configuration to take effect
sysystemctl restart unattended-upgrades.service #The new version of Ubuntu uses Systemctl to manage services
ls /var/log/unattended-upgrades #Logging location

Logging in to the server every day and opening log files is a bit cumbersome. Is there a better way to solve the problem of unattended notification? There are two ways

/etc/apt/apt.conf.d/50unattended-upgrades #In this configuration file, search for the emaiL field and delete"//",The log that can be modified to be updated every day is sent to the administrator's mailbox, or sent to the administrator's mailbox after an error occurs. Regarding the mail service, we will introduce the mail service again
apt install apticron #In addition to modifying the configuration file above, you can also use the application to achieve effects
vi /etc/apticron/apticron.conf #Configuration file path

0 x05 APT update configuration##

vim /etc/apt/sources.list #APT update source configuration file, if it contains CDrom source, comment out
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multivers #The general format is this, the first column indicates the binary installation package or the source package (deb/deb-src), The second column is the URL address of the library, and the third column is the codename of the operating system,The fourth column is the content composition of the library and whether it is officially supported

The meaning of the options in the fourth column

Third-party library

We recommend using the official software library, but sometimes due to different reasons, the official software library is not yet supported. At this time, a third-party software library is needed. It is recommended to create a separate source ".list" file for each third-party library (/ etc/apt/source.list.d). Third-party security also refers to the consideration. Ubntu also provides a verification mechanism that uses GnuPG Key for verification. GnuPG is a public key management system. When installing a third party, you can first obtain the third party's key, import it into the system, and update the index.

add-apt-repository URL #Add a third-party source, the data will be stored in"/etc/apt/sources.list.d/"under,
apt-key add keyname #Import key to local trsted database
apt-key keyname #When uninstalling the third party, delete the unnecessary keys
apt-get update #After updating the index, you can start using third-party libraries

Personal Package Archive (PPA)

The users of the above third-party libraries basically belong to enterprises or institutions. For individual developers, it is too cumbersome to develop and manage the third-party library server. So Ubuntu officially launched a personal software package archive. The official server, storage space and maintenance are provided. The software packages in the PPA have not been reviewed, and the software is released and maintained by individuals. The PPA library is essentially another form of APT software library. The commands are similar to third-party libraries, so I will not demonstrate here.

0 x06 SNAP Package Management##

The foregoing describes the characteristics of the APT package management tool, which has the following shortcomings

For individuals, it is acceptable to upgrade the system and back up the data. The decision to upgrade the system in the enterprise production environment is very difficult. SNAP is a tool born to solve this problem.

But now we use APT package management the most. Teacher Yuan is very optimistic about the development of this tool. O(∩_∩)O haha~

apt install snap #Install snap
snap find name #Find a package
snap install name #Install package
snap remove name #Remove package
snap refresh name #Update the software package, do not add the package name to update the index of the snap

The software packages installed by Snap exist independently (the operating environment and dependencies are independent). So far, Snap is recommended as an important supplement to APT.

0 x07 Reference Link##

Ubuntu Server from entry to master

GnuPG

/VAR/LOG/Analysis of each log file

Recommended Posts

Ubuntu Server Chapter 3 Package Management
Ubuntu Server Chapter 7 Remote Management
Ubuntu package management
Ubuntu Server Chapter 8 DNS Service
Ubuntu Server Chapter 2 Command Line Basics
Ubuntu offline installation package
ubuntu install nginx server
Deploy FTP server under ubuntu
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
ubuntu 16.04 build pptpd V** server
Configure tomcat on ubuntu server
Server upgrade Ubuntu 20.04 LTS record
Build Ubuntu 12.04 cross compilation server
Server upgrade Ubuntu 20.04 LTS record
Ubuntu server builds Java web server
Ubuntu deploys squid proxy server
Initial setup of Ubuntu 16.04 server
Ubuntu16.04 build GitLab server tutorial
Install rgl package under Ubuntu
Build Nginx-RTMP live server on ubuntu
Installation of deb package under Ubuntu
Install Chef server workstation on Ubuntu 18.04
Ubuntu16.04 build php5.6 Web server environment
MySQL connected to remote Ubuntu server
Install Ubuntu 18.04 server with kvm virtualization
Build a file server on ubuntu
Use Ubuntu 16.04 for initial server setup
Install Oracle 11gR2 on Ubuntu Server 12.4.0
Advantages of using apt command to download management package in Ubuntu environment