create account

Fundamentals of Package Management in Ubuntu and Debian p2 by aser1111

View this thread on: hive.blogpeakd.comecency.com
· @aser1111 ·
$11.27
Fundamentals of Package Management in Ubuntu and Debian p2
In this article we will continue to review the fundamentals of package management in Ubuntu and Debian . If you do not read the first part, I recommend that you read it first before continuing to read this article.

![ubunto p2.png](https://steemitimages.com/DQmRLJLCHMDqyyyXURq1VKdvAQWck2DwBPh42SjL1J3zPP6/ubunto%20p2.png)
Remove packages and delete files
Counter-processes for installation and download packages are also available from the package manager. This section will discuss how to uninstall packages and clean up files that may remain as a result of the package.

Remove the package
To remove a stand-by package, you must add the remove command to the apt-get command . This will remove the files that the package installed on your system with a worthwhile exception.

It keeps the settings files saved somewhere if the package is reinstalled again later. This is useful if you suddenly delete the package; you do not waste your effort in resetting and customizing your settings.

To complete the process, you need to supply the command with the name of the package to be removed or canceled:

sudo apt-get remove package
The package will be removed, except for the settings file.

Remove a package and all relevant settings files
If you want to remove a package and all related files from your system, including the configuration files, you can use the purge sub command of the apt-get command . 
Unlike the remove command mentioned above,  purge removes everything. This is useful if you do not want to keep the configuration files, or if you have some problems and want to start from scratch.

Note that the settings files can not be retrieved if they are deleted:

sudo apt-get purge package
In this case, when you re-install the package again, the default settings are used.

Remove automatic dependencies that are no longer needed
Packages are removed from the system using the apt-get remove or apt-get purge commands , but some of these packages may require installation times for some updates to complete the installation. After removing the package, these dependencies remain.

To remove any packages that have been installed as dependencies and are no longer required for any other package, you can execute the autoremove command as follows:

sudo apt-get autoremove
If you want to remove all settings related files from the dependencies that have been removed, you must add purge - to the autoremove command . This command will remove the settings files such as the purge command function :

sudo apt-get --purge autoremove
Clean the obsolete packet files
Some packages become old and deserted over time.

The tool can apt-get remove any files from these packages for the local system, those associated with the packages that are no longer available from the warehouses by using the command files Autoclean .

This command frees more space on the server, allows the cache to be updated on the local system and avoids the retention of unused data.

sudo apt-get autoclean
Get information about packages
Each package contains a large amount of data that can be accessed through the package management tools. In this section we will highlight some common ways to obtain information about available and measurable packages.

View information about a package
To view detailed information about a package in the distribution that you use, you can use the show command from the apt-cache command .

This depends on the package name in the repository:

apt-cache show package
The command will display information about the packages that appear in the product of the search for that package you are inquiring about.

Each candidate package includes information about its reliability, version, format or architecture, conflicts, actual package name, package size and installation size, detailed description, and other information.

To view more information about each candidate package, including a complete list of reverse dependencies (list of packets that depend on the package we are inquiring about), use the showpkg command instead of the above command, which will include a lot of information about the relationship of this package to other packages:

apt-cache showpkg package
View the information about the deb package.
Displays details about the .db file . You can use the info handle - with the dpkg command , the target for this command must be the path of the deb file  . :

dpkg --info debfile.deb
This will show you some metadata about the package you're inquiring about. Information includes the package name and version, the architecture you've built, the size and dependencies you need, the description and the conflicts.

View dependencies and reverse dependencies
To accurately view dependencies (depending on the package), as well as reverse dependencies (packages that depend on this package), you can use the apt-cache tool .

To view the reliability information well, you can use the subscribes command :

apt-cache depends package
The command will display information about each package identified as reliability, as well as suggestions, recommendations, or conflicts.

If you want to know which packages depend on a specific package, you can add the package name to the rdepends sub command :

apt-cache rdepends package
View installed and available package versions
Often, several versions of a package are available in the repository, with one default package. To view the available versions of a package, you can use the policy command from the apt-cache command :

apt-cache policy package
The command will display any installed version (if the package is installed), the filtered package that will be installed by default if you do not specify a version in the installation command, as well as the package version table, ending with an index indicating the priority of each version.

You can use that method to determine which version will be installed and which alternatives are available. Because this method monitors the repositories where each version exists, it can be used to determine if other repositories or PPAs are available to copy packets from the default repository.

Displays the installed packages using the dpkg -l command
To view the packages that are installed on your system, you have few options, depending on the output body, as well as the size of the information required.

The first method involves using dpkg or dpkg-query with l- . The outputs of both will be identical, no doubt will give a list of each package installed (partially or completely) on the system, and form as follows:

dpkg -l
Desired = Unknown / Install / Remove / Purge / Hold
| Status = Not / Inst / Conf-files / Unpacked / halF-conf / Half-inst / trig-aWait / Trig-pend
| / Err? = (None) / Reinst-required (Status, Err: uppercase = bad)
|| / Name Version Architecture Description
+++ - ========================================== - == ======================================== ============ = - =================================================== =============================================== ==================
ii account-plugin-generic-oauth 0.10bzr13.03.26-0ubuntu1.1 amd64 GNOME Control Center account plugin for single signon - generic OAuth
ii accountsservice 0.6.34-0ubuntu6 amd64 query and manipulate user account information
ii acl 2.2.52-1 amd64 Access control list utilities
ii acpi-support 0.142 amd64 scripts for handling many ACPI events
ii acpid 1: 2.0.18-1ubuntu2 amd64 Advanced Configuration and Power Interface event daemon
. . .
Outputs for each package in the system will continue to output. You can see the first three characters of each line. The first character indicates the desired state of the package, and is one of the following:

u : Unknown
i : Installed
r : has been removed.
p : completely removed (clean after removal)
h : Pending version.
The second character refers to the actual state of the package as known to the packaging system, which can be one of the following situations:

n : Not installed.
i : Installed.
c : The settings file exists, but the package has been removed.
u : The package has been decompressed but not yet set up.
f : The package is set up (partially), which means a failure during the installation process, which did not allow the installation to complete.
w : The package is waiting for an event from a separate package.
p : The package has been activated by other package.
The third letter, which is a blank space for most packets, has one option as follows:

r : A reference to the need to re-install, which means that the package is incomplete and can not take advantage of its functions.

The rest of the columns contain the package name, version, architectural as well as description.

View the installation status of the packets you have nominated
If you add a search criteria after  l- , dpkg will display all packages that contain the search criteria, whether or not they are installed. For example, we can search for YAML library operations as follows:

dpkg -l libyaml *
Desired = Unknown / Install / Remove / Purge / Hold
| Status = Not / Inst / Conf-files / Unpacked / halF-conf / Half-inst / trig-aWait / Trig-pend
| / Err? = (None) / Reinst-required (Status, Err: uppercase = bad)
|| / Name Version Architecture Description
+++ - =============== - ============ - ============ - ==== ==================================
ii libyaml-0-2: amd 0.1.4-2ubunt amd64 Fast YAML 1.1 parser and emitter li
ii libyaml-dev: amd 0.1.4-2ubunt amd64 Fast YAML 1.1 parser and emitter li
un libyaml-perl                       (no description available)
un libyaml-syck-pe                      (no description available)
ii libyaml-tiny-pe 1.51-2 all Perl module for reading and writing
As you can see in the first column, the third and fourth result are non-aligned. This command displays each package where the search criteria are available, as well as the current and desired status.

Displays the packages created with the dpkg -get-selections command
You can browse the packages installed on your system in another way, using the get-selections index - with the dpkg tool . This provides us with a list of all installed packages that were removed without cleaning after removal:

dpkg --get-selections
To differentiate between these two situations, you can use awk to filter by status. To view only installed packages, print:

dpkg --get-selections | awk '$ 2 ~ / ^ install / `
To view the list of removed packages but not the settings files, you can use the command:

dpkg --get-selections | awk '$ 2! ~ / ^ install /'
Search within installed packages
To search packages made for a particular package, you can add the filter / filter text after the get-selections option . This uses alternatives to try to find a match. Again, this command displays any installed package, or its configuration files are still on the system:

dpkg --get-selections libz *
Again, you can filter using awk expressions from the section above.

Browse files installed through a package
To browse files for a package, you can use the L- pointer  with the dpkg command :

dpkg -L package
This will print the full path of each file for that package. Of course, the menu will not include the settings files that are created through the package operations

Search for what the package installs for a site
To troubleshoot any package that is responsible for a particular file in the file system, you can add the full file to the dpkg command with the S- pointer  .

The command will print the name of the package that installed the file:

dpkg -S / path / to / file
Note that any files that have been moved somewhere through the post-installation process can not be linked to their resolution through this command.

Know which package you are providing with a file without installing it
You may sometimes need to know which package is providing you with a file or something, even without installing the package on your system. It is easy to tell if a particular package contains a file using dpkg by adding the S- option .

To do this, you must install the apt-file tool . This tool has a database of package information, including the installation path for each package file from that database.

Install the tool by:

sudo apt-get update
sudo apt-get install apt-file
Now, update the tool's database and search for a file with:

sudo apt-file update
sudo apt-file search / path / to / file
This will only work for sites that have been directly installed by a package. Files created with post-installation programs will not be found.

Converts packages between systems
Often you may need to back up the list of packages that have been installed on your system, and use it to install the same list of packages on another system. Of course, this method is useful for backup purposes. This section explains the mechanism for exporting and importing packages lists.

Export the list of packages
If you want to duplicate the package of packages installed on your system to another system, you must first export the list of packages.

You can export the list of packages that are installed to a file in the format that is required later for the import process by the output of the command dpkg -get-selections :

dpkg --get-selections> ~ / packagelist.txt
You can copy this list to another system or computer and import it.

You may also need to take a backup of the source lists and the list of trusted keys. You can take a backup of the resources by creating a folder with the necessary files and copying them:

mkdir ~ / sources
cp -R /etc/apt/sources.list* ~ / sources
Trusted keys can be backed up by:

apt-key exportall> ~ / trusted_keys.txt
Now you can convert the packagelist.txt file, the sources folder, and the trusted_keys.txt file to another computer for import.

Import the list of packages
If you create a package list using dpkg -get-selections as explained above, you can import the packages on another computer using the dpkg command .

You must first add the trust keys, and prepare the source lists that were copied from the first computer. Assuming you copied all the files transferred to the home folder on the second computer, you can perform:

sudo apt-key add ~ / trusted_keys.txt
sudo cp -R ~ sources / * / etc / apt /
Then, remove the case from unnecessary packages from the new computer. This means that you are applying the changes again. This should be implemented through a root account or sudo:

sudo dpkg --clear-selections
The command will select all packages that you do not want to install. You must also update the list of local packages to ensure that the installation processes will have a record or information for all programs that need to be installed. The actual installation and talk process will be processed through the dselect tool .

Make sure the dselect tool is installed. This tool has its own database, so it must be updated before updating:

sudo apt-get updateH
sudo apt-get install dselect
sudo dselect update
Now we can apply the list of packages above the current list; to see which packages should be kept or uploaded:

sudo dpkg -set-selections <packagelist.txt
This command adjusts the packets we want. To apply the changes, you must implement the dselect-upgrade command from the apt-get command :

sudo apt-get dselect-upgrade
This will load and install the necessary packages. It will remove packages that are not selected. Finally, the list of packages must match those imported from the first computer, regardless of whether the configuration files still need to be copied or modified.

Add repositories and personal archive of PPA packages
The default set of repositories provided in most distributions contains sufficient packages for most users. However, you often need additional resources. In this section we will discuss the mechanism of numbering packages to deal with additional resources.

Add a personal archive of packages
Personal Packet Archive (PPAs) is a substitute for traditional repositories. The Personal Packet Archive is only available for Ubuntu systems, as of this article. A personal archive of packets is typically characterized by a smaller domain than repositories, and contains a centralized set of applications that are maintained by those who own the personal archive of packages.

Add a package profile archive to your system, allowing you to manage the packages it contains with the package management tools you are used to. This method will provide us with a package or set of updated packages that are not included in the distribution package repository. Note that you need to add the personal archive of the packages you trust, since you allow an unofficial folder to build packages for your system.

To add a personal archive of packages, you can use the add-apt-repository command . You must add the name ppa:, followed by the name of the owner of the personal archive of the packages on the Launchpad , the slash and then the personal archive name of the packages:

sudo add-apt-repository ppa: owner_name / ppa_name
You may need to agree to accept the carrier key. The personal archive of the packages will then be added to your system, allowing you to install packages with the usual apt commands . Before searching for or installing packages, you've made sure to update your local cache with information about your new profile archive:

sudo apt-get update
Add repositories
To add more repositories to Ubuntu or Debian systems, you can follow one of two paths.

The first path is to modify your source lists directly. You can modify the / etc / sources / list file or replace a new list file in the /etc/apt/sources.list.d/ folder . If you use method 2, note that the file name that you created must end with a list. :

sudo nano /etc/apt/sources.list.d/new_repo.list
You can add the new repository location in the new file using the following format:

deb_or_deb-src url_of_repo release_code_name_or_suite component_names
The different parts of warehouse specifications are as follows:

deb or  deb-src : Specifies the type of repository. Deb is used to specify the normal repository, while resource repositories start with deb-src .
url : The main address of the warehouse. The location in which the warehouse is located must be located.
release code name or suite : Usually the official name of the distribution version, but it may be any user name to define a specific set of packages created for the version you are using from the distribution.
component names : Select the packages you want to provide. An advantage is provided by the distributors to provide an explanation of the credibility or licensing limitations of the software they contain.
You can add these lines inside the file. Most repositories contain information about which body to use.

Another way to add more repositories is by using the add-apt-repository command . Ubuntu distributions By default, this command can be installed into Debian distributions through the software-properties-common package :

sudo apt-get update
sudo apt-get install software-properties-common
You can then add the lines that you want to add to the add-apt-repository command . Of course, extensions must be the same body or shape that you use in the case of manual extensions:

sudo add-apt-repository 'deb url release component'
Be sure to update the local packet cache after applying any update to the repository so that the system is aware of the newly available packages:

sudo apt-get update
Conclusion
There are many package management processes you can do, but we've tried to cover most common steps here. If you have any other preferences or concerns, please use the comments section below to know them.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 98 others
properties (23)
authoraser1111
permlinkfundamentals-of-package-management-in-ubuntu-and-debian-p2
categoryubuntu
json_metadata{"tags":["ubuntu","steemthat","brograming","utopian-io"],"image":["https://steemitimages.com/DQmRLJLCHMDqyyyXURq1VKdvAQWck2DwBPh42SjL1J3zPP6/ubunto%20p2.png"],"app":"steemit/0.1","format":"markdown"}
created2018-04-20 21:03:45
last_update2018-04-20 21:03:45
depth0
children1
last_payout2018-04-27 21:03:45
cashout_time1969-12-31 23:59:59
total_payout_value8.816 HBD
curator_payout_value2.454 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length19,639
author_reputation3,224,691,028,416
root_title"Fundamentals of Package Management in Ubuntu and Debian p2"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id51,192,683
net_rshares1,947,137,095,527
author_curate_reward""
vote details (162)
@hhod ·
Sephiroth
The Tree of Life, or Etz haChayim (עץ החיים) has upvoted you with divine emanations of G-ds creation itself ex nihilo. We reveal Light by transforming our Desire to Receive for Ourselves to a Desire to Receive for Others. I am part of the Curators Guild (Sephiroth), through which Ein Sof (The Infinite) reveals Itself!
👍  
properties (23)
authorhhod
permlinkfundamentals-of-package-management-in-ubuntu-and-debian-p2
categoryubuntu
json_metadata{"tags":"sephiroth","app":"sephiroth/1.0","format":"markdown+html","community":"sephiroth"}
created2018-04-23 21:39:24
last_update2018-04-23 21:39:24
depth1
children0
last_payout2018-04-30 21:39:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length319
author_reputation46,455,166,745
root_title"Fundamentals of Package Management in Ubuntu and Debian p2"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id51,750,609
net_rshares2,038,253,284
author_curate_reward""
vote details (1)