What’s deb?
Deb is a file extension for the Debian faction Linux distribution package format. Deb packages are similar to Windows packages (exe) on Linux and require little or no complicated compilation to install with a click of the mouse. Common Linux factions are:
The Fedora faction’s package is a package with an extension named RPM, which we will not expand here. In this note we introduce deb packages using Ubuntu as an example.
There are two ways to install an application deb in Ubuntu desktop. One is to double-click the deb to install it. The other is to install by command, such as:
sudo dpkg -i xxx.deb
Copy the code
DPKG (Debian Packager) is a deb package management tool that can be used to install, update, and uninstall DEB packages.
Uninstallation commands are as follows:
sudo dpkg -r xxx
Copy the code
What is APT?
Apt (Advanced Package Tool) is also a deb Package management Tool. The DPKG (Debian Packager) package management tool mentioned above is mainly used to install deb packages that we downloaded locally. The APT package management tool can directly search and install software from Ubuntu official server software repository to our Ubuntu system, and can also update and uninstall our DEB software through apt tool.
The software in the Official Ubuntu software Repository is strictly approved and of guaranteed quality. Software developed by third-party developers must pass the official certification before being placed in the official Ubuntu software Repository.
In order to have a clearer understanding of APT and DPKG package management tools, we take the installed software on mobile phones to do a comparison:
Use APT to install software in Ubuntu, for example, our mobile phone directly downloads software from the app store for installation, and we will be informed to update the software in the app store later. Ubuntu uses DPKG to install software such as the software we download in the mobile browser, which needs to be installed manually.
The differences and connections between APT and DPKG are as follows:
- The DPKG is used to install.deb files, but does not resolve module dependencies, and does not care about software in Ubuntu’s repository. It can be used to install local deb files.
- Apt resolves and installs module dependencies and consults repositories, but does not install native DEB files. Apt is a software management tool built on top of DPKG.
Use APT to install software
We can use the following apt command to install the software:
sudo apt-get install xxx
Copy the code
XXX indicates the software to be installed.
For example, we can enter sudo apt-get install sl to install sl software. Sl software is an interesting software, after running the SL command, our terminal will appear a small train:
After we input the above command to install SL software, we will download and install SL software from the official software source. Ubuntu’s official repository address:
cn.archive.ubuntu.com/ubuntu
This address is saved in /etc/apt/source.list. Sudo apt-get install will download the package from the server address of the file.
The network environment of each place around the world is different, so there are mirror servers around the world, such as tsinghua software source, Ali Cloud software source, University of Science and Technology of China software source.
We can add one of our domestic software sources to /etc/apt/source.list, so that when we use sudo apt-get install to install the software, we will download the software from our domestic image server, which will be much faster. For Ubuntu with a GRAPHICAL interface, we can also select the image server in software Update, such as:
The selection here will automatically be in/etc/apt/source.list
Add related server addresses, such as:
Change is good/etc/apt/source.list
We need to use the file latersudo apt-get update
Command to update the list of software available for download in the server:
One function of the app list is to help us update the app, because the app on the server is constantly updated, just like the app in our mobile app store is constantly updated, and if there is an update, it will remind us to update it.
If we want to update the software, we can run sudo apt-get upgrade to update the installed software:
Finally, the command for uninstalling the software is:
sudo apt-get remove
Copy the code
Make your own DEB package
If necessary, we can also make our own software packages.
Deb packages are our application packages that contain executable files, package names, version numbers, and other documentation. A DEB needs to create a new folder to manage the required files before making them, such as:
Where usr/local/bin indicates that deb’s default installation path is /usr/local/bin (which is the “official path” of the system). Default installation path You can change the folder name. For example, if you change usr/local/bin to home/ZhengN/, the default installation path of the software package will be home/ZhengN.
Let’s create a deb package for HelloDeb as shown above. For convenience, we will add the necessary control files in DEBIAN. Other files will not be added for the time being. The structure is as follows:
Create a hellodeb.c file:
#include <stdio.h>
int main(void)
{
printf("hellodeb\n");
return 0;
}
Copy the code
Compile using GCC to get a HelloDeb executable. Copy to hellodeb/usr/local/bin.
2. Prepare a control file:
Package: HelloDeb Version:1.0 Architecture: AMd64 Maintainer:ZhengN Description:debtest
Copy the code
Place the control file in the hellodeb/DEBIAN directory.
Our hellodeb directory now has:
To generate a deb package, run the following command in the hellodeb directory:
sudo dpkg-deb -b .. /hellodeb .. / hellodeb_1. 0 _amd64. DebCopy the code
Hellodeb_0_x64. deb = helloDeb_0_x64. deb = helloDeb_0_x64. deb = helloDeb_0_x64. deb
Run the following command in the helloDeb_1.0_x64. deb directory to install the package:
Sudo DPKG -i hellodeb_1. 0 _amd64. DebCopy the code
/usr/local/bin = /usr/local/bin = /usr/local/bin
We can run hellodeb from any path on the terminal:
We can uninstall hellodeb with the following command:
sudo dpkg -r hellodeb
Copy the code
An error will be reported if you try again after uninstallation:
bash: /usr/local/bin/hellodeb: No such file or directory
Copy the code
Thanks for reading.