Linux system offline installation package and its dependent download and installation

I. Overview

  When we develop projects under the Linux system, there are often situations where some dependent libraries or development packages are missing. At this time, we usually use the apt command to download from the Internet. However, in some special cases (for example, the terminal hardware does not support network connection, the surrounding area lacks wired and wireless networks, or the program needs to be installed on many terminals in batches), we need to download the corresponding dependent environment installation package first, and then Copy it to the corresponding terminal and install it manually. The following is a summary of the knowledge about downloading and installing offline installation packages and dependent packages for Linux systems.


2. APT-Linux software package management tool

  APT (Advanced Packaging Tool), is a command-line utility and a software package management system that works on Debian, Ubuntu and other related linux distributions. It provides features such as automatic retrieval, configuration, and installation of software packages to simplify software management. Through the apt command, you can search, install, upgrade, and uninstall software from Internet software warehouses. Most apt commands must be run as a user with sudo privileges.
  APT commands can be simply divided into two categories, one is apt-xxx (such as apt-get, apt-cache) series commands, and the other is apt. Both can be used to process software packages, but the apt-xxx series of commands will divide and disperse the management operations of software packages, which is not very friendly to novice terminal users. On the basis of the original apt-get and apt-cache, apt simplifies and optimizes the basic software package management operations. It is a command-line tool specially designed for novice end users, and can be regarded as a subclass of apt-get and apt-cache commands. set, which can provide necessary command options for package management.
insert image description here

As can be seen from the above table, using the apt command, we don't need to pay attention to whether we need to use the apt-get or apt-cache command when performing different operations, which simplifies the package command operation. However, since the apt command is designed for end users, the interactivity of basic software package management operations has been improved compared with the traditional apt-xxx command, but this is obtained by sacrificing backward compatibility, so in In scenarios such as scripts, traditional apt-xxx commands that emphasize backward compatibility should be used. And because apt is a command aimed at simplifying basic software package management operations, many advanced operations, such as using apt-mark to fix the software package version, are not involved at all, so when some advanced operations on software packages are needed , you should use the apt-xxx command. When performing some basic operations on software packages, you can use the apt command.

1. Grammar

apt [options] [command] [package ...]
  • options: optional, options include -h, -y, etc.
  • command: the operation to be performed.
  • package: The name of the package to be operated on.

2. Common options

options effect
-h show help information
-y Respond yes in scenarios requiring confirmation
-v Display the detailed version number of APT
-d only download, not install
-f Attempt to fix broken system dependencies

3. Commonly used commands

Order effect
list list packages by name
search Search package descriptions
show show package details
install install package
reinstall reinstall the package
remove remove package
autoremove Uninstall any automatically installed packages that are no longer in use
update Update the list of available packages
upgrade Update the system by installing/upgrading software
full-upgrade Update the system by uninstalling/installing/upgrading
edit-sources Edit the software source information file
download download

The following is a brief description of commonly used apt commands:

1)sudo apt update

Update the list of available packages from the remote repository to the local. If it is not updated for a long time, the new version of the software package will not be downloaded and installed by other apt related commands.

2)sudo apt upgrade [package_name]

If a package name is specified, the specified package will be upgraded; if no package name is specified, all updatable packages will be upgraded. (If upgrading a package requires uninstalling other packages, it will not be processed)

3)sudo apt [-y] [-d] install package_name1 [package_name2] …

Install the specified software package. If multiple packages are installed, use spaces to separate them. It can also be used to install local deb files. You can add the "-y" option to skip the confirmation step in the installation process; you can add the "-d" option to download the corresponding software offline installation package. The default storage location of the downloaded package is /var/cache/apt/ archives.

4)sudo apt remove package_name1 [package_name2] …

Uninstall the specified software package. If multiple packages are to be uninstalled, separate them with spaces. Use remove to keep the configuration file, use purge to completely remove the package.

5)apt download package_name

Download the specified software package, and the storage location is the directory where the window that executes the command is located.

6)sudo apt list

Show all available packages. The following extended usages exist:

  • Check if a package is available

sudo apt list | grep package_name

  • View installed packages

apt list --installed

  • View upgradeable packages

apt list --upgradeable

7)apt search package_name

Used to search for specific packages.

8) sudo apt autoremove

Clean up dependencies and library files that are no longer used.


三、dpkg

  "dpkg" is short for "Debian Packager". A package management system specially developed for Debian to facilitate software installation, update and removal. All Linux distributions derived from Debian use dpkg, such as Ubuntu, Knoppix, etc.
  dpkg is the basis of the Debian package manager, which was created in 1993 by Ian Murdoch. dpkg is very similar to RPM and is also used to install, uninstall, and provide information about .deb packages. dpkg itself is a low-level tool. Upper-level tools, such as APT, are used to obtain packages remotely and handle complex package relationships.

1. Grammar

dpkg [options] [package ...]
  • options: options.
  • package: The package to operate on.

2. Common options

options effect
-i install package
-r remove package (keep config)
-P remove package (remove config)
-l Show list of installed packages
-L Show files associated with a package
-c Display a list of files within a package file
-s Find package details
-x Unzip the files in the software package to the specified directory
-X Unzip the files in the software package to the specified directory and print it on the command line

3. Common usage of dpk command

1)sudo dpkg -i [–force-overwrite] package_name.deb

Install the specified package file. The file name must have an absolute path or a relative path. If multiple deb packages are installed at the same time, they can be separated by spaces. Add the --force-overwrite parameter to perform forced overwrite installation, which can be used to solve the problem of failure to try to overwrite some libraries when installing the deb package.

2)sudo dpkg -r package_name

Uninstall the specified package.

3)dpkg -l [package_name]

Display the version information of the specified installed software package, or display the list information of all installed software packages if no software package name is specified.

4)dpkg -L package_name

Display the files associated with the software package, which can be used to view the directories where the specified software package is installed.

insert image description here

5)dpkg -c package_name.deb

Display the list of files in the package file, the effect is similar to -L, but -L is for the installed software, and -c is for the package deb file.

insert image description here

6)dpkg -X package_name.deb xxx

Unzip the files in the specified deb package to the specified xxx directory, and print out all directory and file names on the command line.


4. Download and install the installation package and its dependencies

The following is an example of downloading the build-essential installation package on the UOS system version 1050.

1. Obtain the name of the dependent software package required to install the build-essential software in the current system

Open the terminal and enter the sudo apt install build-essential command, but do not agree to the installation, so that you can see the name of the package that will be installed or upgraded when downloaded online.

insert image description here

As can be seen from the figure above, if we install the build-essential software package online through the apt command, a total of four software packages, build-essential, g++, g+±8, and libstdc+±8-dev, will be installed at this time. We can use the apt depends command to view the dependencies of the corresponding software package.

insert image description here

insert image description here

insert image description here

Among them, build-essential is the target software package. The current system lacks g++ dependencies, and g++ lacks g+±8 dependencies, and g+±8 lacks libstdc+±8-dev dependencies. In this way, we directly obtain the dependencies and dependencies that build-essential currently lacks in the system.

2. Download the offline installation package

Use the apt download command to download the software packages required in step 1.

insert image description here

insert image description here

3. Install the software package offline

You can simply write a sh script to install the software package and its dependencies for easy operation. The function implemented in the script is very simple, that is, to install multiple deb packages with one dpkg command, so that you don’t need to care about the dependency order of these deb packages. Before executing the script, remember to use the ls -l command to check whether the sh script file has execution permission. If not, use the chmod command to grant execution permission.

insert image description here

insert image description here

insert image description here

Additional instructions

If we only install the deb package of build-essential without installing its dependent packages, the following prompt will appear:

insert image description here

At this point, we can use the sudo apt -f install or sudo apt --fix-broken install command to fix the current system dependencies. As can be seen from the figure, it also prompts that g++, g+±8 and libstdc+±8 are missing -dev these three dependent packages.

insert image description here

You can also refer to the following article ( apt downloads all dependent packages with one click ), and downloads all dependent packages with one click through a combination of shell commands.


reference

  1. APT、apt-get、apt-cache 和 apt
  2. apt command in linux
  3. Linux system dpkg command

Guess you like

Origin blog.csdn.net/weixin_56291477/article/details/127074917