Difference between revisions of "Package management in Ubuntu"

From Notes_Wiki
m
m
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
<yambe:breadcrumb>Ubuntu|Ubuntu</yambe:breadcrumb>
[[Main Page|Home]] > [[Ubuntu]] > [[Ubuntu Server or Desktop administration|Server or Desktop administration]] > [[Package management in Ubuntu]]
=Package management in Ubuntu=


==Package management commands==
==Package management commands==
Line 72: Line 71:
<pre>
<pre>
apt-file search <file-path>
apt-file search <file-path>
</pre>
===Verify files installed by package against their checksums===
To verify file against their checksums use:
<pre>
dpkg --verify <package-nam>
</pre>
There is also '<tt>debsums</tt>' command to validate installed files with following options:
; -a : To verify configuration files also
; -e : To verify only configuration files
; -c : Print changes to stdout
; -l : List packages for which we dont have MD5 checksums file
===List files that are installed due to a package===
We can list files installed due to a specific package via:
<pre>
dpkg -L <package-name>
</pre>
===Check when a package was installed===
To check when a package was installed on current system use:
<pre>
grep " install" /var/log/dpkg.log | grep " example-package "
</pre>
Here, replace " example-package " with actual package.  Note the spaces before and after the package name
===Fix missing packages===
If a deb package (Eg teamviewer) is installed using:
<pre>
    sudo dpkg -i <deb-package>
</pre>
Then many of its dependencies might be missing.  To solve that use:
<pre>
    sudo apt-get update --fix-missing
    sudo dpkg --configure -a
    sudo apt-get install -f
</pre>
After this check the debian package installed and validate whether it is working properly. 
Refer:
* http://www.iasptk.com/ubuntu-fix-broken-package-best-solution/
===Search package to which particular file belongs===
To check which package a particular file belongs use:
<pre>
dpkg -S <full-path-to-file>
</pre>
</pre>


Line 106: Line 161:
Example installation script for postfix using debconf-set-selections is:
Example installation script for postfix using debconf-set-selections is:
<pre>
<pre>
   echo "postfix postfix/root_address string saurabh@sbarjatiya.com" | sudo debconf-set-selections
   echo "postfix postfix/root_address string saurabh@example.com" | sudo debconf-set-selections
   echo "postfix postfix/mailname string localhost" | sudo debconf-set-selections
   echo "postfix postfix/mailname string localhost" | sudo debconf-set-selections
   echo "postfix postfix/destinations string localhost" | sudo debconf-set-selections
   echo "postfix postfix/destinations string localhost" | sudo debconf-set-selections
Line 116: Line 171:




<yambe:breadcrumb>Ubuntu|Ubuntu</yambe:breadcrumb>
==Fixing broken apt-database or unmet dependencies issues==
 
It is possible to install packages via dpkg or apt (esp with force option) such that the dependency of all installed packages is not met properly.  To fix such issues we may have to use one of the below to solve the problem ('''Not all of below are required in all enviornments, use appropriate based on issue being faced)''':
# Stop all running apt / update processes in background and try:
#:<pre>
#:: apt-get -f install
#:</pre>
# Try fixing broken installs with:
#:<pre>
#:: apt --fix-broken install
#:</pre>
# To remove package with dependencies try:
#:<pre>
#:: sudo apt-get --purge autoremove <package-name>
#:: OR
#:: sudo apt-get purge <PACKAGENAME>
#:: sudo apt-get purge $(apt-cache depends <PACKAGENAME> | awk '{ print $2 }' | tr '\n' ' ')
#:: sudo apt-get autoremove
#:: sudo apt-get update
#:: sudo apt-get check
#:: sudo apt-get -f install
#:: sudo apt-get autoclean
#:</pre>
# While installing packages prefer apt over dpkg via:
#:<pre>
#:: apt install ./<local-deb-file>
#:</pre>
 
 
Refer:
* https://superuser.com/questions/1386209/how-to-solve-this-dependencies-apt-fix-broken-install
* https://askubuntu.com/questions/708701/using-apt-get-to-remove-packages-and-dependencies
* https://linuxize.com/post/how-to-install-deb-packages-on-ubuntu/
* https://askubuntu.com/questions/527410/what-is-the-advantage-of-using-sudo-apt-get-autoremove-over-a-cleaner-app
 
 
[[Main Page|Home]] > [[Ubuntu]] > [[Ubuntu Server or Desktop administration|Server or Desktop administration]] > [[Package management in Ubuntu]]

Latest revision as of 04:51, 10 April 2024

Home > Ubuntu > Server or Desktop administration > Package management in Ubuntu

Package management commands

Update package metadata

To get list of latest packages from repository servers use:

sudo apt-get update


Install package

To installing package use:

sudo apt-get install <package-name>


Searching package

To search for a package with name or word in description use:

apt-cache search <word>


List installed packages

To get list of all installed packages use:

dpkg --get-selections


Package information

To get information about package use:

apt-cache show <package-name>


Removing package cache

To delete complete cache, except locks, use:

apt-get clean


Removing obsolete packages

To remove packages that are no longer avaialble in parent repo for download from local apt-cache use:

apt-get autoclean


Packages required for given package

Sometimes a package would require some other package or library to be installed for it to function properly. List of such dependencies can be obtained using:

apt-cache depends <package-name>


Packages that need given package

It is possible that a given package 'A' is required by some other installed package 'B' where 'B' depends on 'A' for it to function properly. To obtain list of all reversly dependent packages [B] for package A use:

apt-cache rdepends <package-name>


Package which created given file

To find package that provides given file, 'apt-file' program can be used. Install apt-file using 'sudo apt-get -y install apt-file' and update its cache using 'sudo apt-file update'. Then to find to which package a particular file belongs use:

apt-file search <file-path>


Verify files installed by package against their checksums

To verify file against their checksums use:

dpkg --verify <package-nam>

There is also 'debsums' command to validate installed files with following options:

-a
To verify configuration files also
-e
To verify only configuration files
-c
Print changes to stdout
-l
List packages for which we dont have MD5 checksums file


List files that are installed due to a package

We can list files installed due to a specific package via:

dpkg -L <package-name>


Check when a package was installed

To check when a package was installed on current system use:

grep " install" /var/log/dpkg.log | grep " example-package "

Here, replace " example-package " with actual package. Note the spaces before and after the package name



Fix missing packages

If a deb package (Eg teamviewer) is installed using:

    sudo dpkg -i <deb-package>

Then many of its dependencies might be missing. To solve that use:

    sudo apt-get update --fix-missing
    sudo dpkg --configure -a
    sudo apt-get install -f

After this check the debian package installed and validate whether it is working properly.

Refer:


Search package to which particular file belongs

To check which package a particular file belongs use:

dpkg -S <full-path-to-file>


Package management tools

Package management tools supported by Ubuntu are:

aptitude
ncurses based
synaptic
Graphical


Learn more at https://help.ubuntu.com/community/AptGet/Howto



Miscellaneous issues

Copying apt-cache

To copy apt-cache from one machine to other so that the same packages do not get downloaded from Internet again copy contents of folder '/var/cache/apt' to other machine.


Installing Ubuntu packages in background

To install Ubuntu packages in background use:

sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q <package-name>

Learned from http://askubuntu.com/questions/339790/how-can-i-prevent-apt-get-aptitude-from-showing-dialogs-during-installation

A better way is to provide default values using debconf-set-selections. debconf-show can be used to see possible parameters for which values can be provided.

Example installation script for postfix using debconf-set-selections is:

   echo "postfix postfix/root_address string saurabh@example.com" | sudo debconf-set-selections
   echo "postfix postfix/mailname string localhost" | sudo debconf-set-selections
   echo "postfix postfix/destinations string localhost" | sudo debconf-set-selections

   sudo DEBIAN_FRONTEND=noninteractive apt-get -y install postfix mailutils
   sudo cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf
   sudo service postfix restart


Fixing broken apt-database or unmet dependencies issues

It is possible to install packages via dpkg or apt (esp with force option) such that the dependency of all installed packages is not met properly. To fix such issues we may have to use one of the below to solve the problem (Not all of below are required in all enviornments, use appropriate based on issue being faced):

  1. Stop all running apt / update processes in background and try:
    apt-get -f install
  2. Try fixing broken installs with:
    apt --fix-broken install
  3. To remove package with dependencies try:
    sudo apt-get --purge autoremove <package-name>
    OR
    sudo apt-get purge <PACKAGENAME>
    sudo apt-get purge $(apt-cache depends <PACKAGENAME> | awk '{ print $2 }' | tr '\n' ' ')
    sudo apt-get autoremove
    sudo apt-get update
    sudo apt-get check
    sudo apt-get -f install
    sudo apt-get autoclean
  4. While installing packages prefer apt over dpkg via:
    apt install ./<local-deb-file>


Refer:


Home > Ubuntu > Server or Desktop administration > Package management in Ubuntu