Ubuntu package: Difference between revisions

From 太極
Jump to navigation Jump to search
 
(49 intermediate revisions by the same user not shown)
Line 2: Line 2:
* https://help.ubuntu.com/community/AptGet/Howto#Maintenance_commands
* https://help.ubuntu.com/community/AptGet/Howto#Maintenance_commands
* [http://www.tecmint.com/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management/ 25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management]
* [http://www.tecmint.com/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management/ 25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management]
* [http://askubuntu.com/questions/766823/apt-get-being-replaced-with-apt apt-get being replaced with apt? in Ubuntu 16.04] '''apt''' now comes with a progress bar, coloring, etc.  
* [http://askubuntu.com/questions/766823/apt-get-being-replaced-with-apt apt-get being replaced with apt? in Ubuntu 16.04] '''apt''' now comes with a progress bar, coloring, etc.
 
= Security of deb packages =
[https://www.makeuseof.com/how-deb-packages-are-backdoored-how-to-detect-it/ How DEB Packages Are Backdoored and How to Detect It]


= [https://en.wikipedia.org/wiki/Wajig wajig]: Simplyfying Debian Administration =
= [https://en.wikipedia.org/wiki/Wajig wajig]: Simplyfying Debian Administration =
Line 11: Line 14:
* Examples
* Examples
** [https://rattle.togaware.com/rattle-install-ubuntu.html Install Rattle] on Ubuntu
** [https://rattle.togaware.com/rattle-install-ubuntu.html Install Rattle] on Ubuntu
= GNOME software =
* https://en.wikipedia.org/wiki/GNOME_Software
* [https://technastic.com/gnome-software-center-on-chrome-os/ How to Install GNOME Software Center on Chrome OS]
* When I use GNOME software to install "okular", the application is not found in the regular path? When I use it to open a pdf file, I see a new process "bwrap --args 36 okular XXX.pdf".
= nala =
* https://gitlab.com/volian/nala, https://github.com/volitank/nala
* [https://ostechnix.com/nala-commandline-frontend-for-apt/ Nala – A Feature-rich Commandline Frontend For APT Package Manager]. Nala ships with the following distinct features out of the box.
** Pretty output formatting,
** History function,
** Parallel downloads,
** Fetch fastest mirror.
* [https://trendoceans.com/nala-package-manager/ Nala: A Beautiful and Structured Frontend for the APT Command]


= Package repository and /etc/apt/sources.list =
= Package repository and /etc/apt/sources.list =
Line 38: Line 55:
</syntaxhighlight>
</syntaxhighlight>


= sources.list.d =
== sources.list.d ==
This directory has more contents than the /etc/apt/sources.list file. For example, on my Mint 17.2
This directory has more contents than the /etc/apt/sources.list file. For example, on my Mint 17.2
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
Line 63: Line 80:
sudo apt-get install syncthing
sudo apt-get install syncthing
</syntaxhighlight>
</syntaxhighlight>
== Remove a repository ==
<pre>
sudo add-apt-repository --remove ppa:<ppa_name>
sudo add-apt-repository -r ppa:<ppa_name>
</pre>
== GPG ==
A Practical Guide to GPG.
* [https://www.linuxbabe.com/security/a-practical-guide-to-gpg-part-1-generate-your-keypair Part 1 Generate Your Keypair],
* [https://www.linuxbabe.com/security/a-pratical-gpg-guide-part-2-encrypt-and-decrypt-message Part 2 Encrypt and Decrypt Message],
* [https://www.linuxbabe.com/security/a-practical-guide-to-gpg-part-3-working-with-public-key Part 3 Working with Public Key],
* [https://www.linuxbabe.com/security/a-practical-guide-to-gpg-part-4-digital-signature Part 4 Digital Signature].
{{Pre}}
$ sudo apt update  # today is 10/22/2020
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ InRelease: The following signatures were invalid: EXPKEYSIG 51716619E084DAB9 Michael Rutter <[email protected]>
...
</pre>
[https://askubuntu.com/a/291095 How to add a GPG key to the apt sources keyring?]
<pre>
wget -qO - https://deb.opera.com/archive.key | sudo apt-key add -
$ apt-key list
/etc/apt/trusted.gpg
--------------------
...
pub  rsa2048 2010-10-19 [SCA] [expired: 2020-10-16]
      E298 A3A8 25C0 D65D FD57  CBB6 5171 6619 E084 DAB9
uid          [ expired] Michael Rutter <[email protected]>
...
</pre>
The solution is to run the '''sudo apt-key''' again.
{{Pre}}
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ apt-key list
pub  rsa2048 2010-10-19 [SCA] [expires: 2027-09-30]
      E298 A3A8 25C0 D65D FD57  CBB6 5171 6619 E084 DAB9
uid          [ unknown] Michael Rutter <[email protected]>
sub  rsa2048 2010-10-19 [E] [expires: 2027-09-30]
</pre>
An example for installing [https://cran.r-project.org/bin/linux/ubuntu/ R software] on Ubuntu
{{Pre}}
sudo apt update -qq
sudo apt install --no-install-recommends software-properties-common dirmngr
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# -qO- will print to standard output screen
# If we use "-q", it will save to the disk
gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# pub  rsa2048 2010-10-19 [SCA] [expires: 2027-09-30]
#      E298A3A825C0D65DFD57CBB651716619E084DAB9        <--- fingerprint
# uid                      Michael Rutter <[email protected]>
# sub  rsa2048 2010-10-19 [E] [expires: 2027-09-30]
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
</pre>
More info:
* [https://itsfoss.com/key-is-stored-in-legacy-trusted-gpg/ Fixing "Key is stored in legacy trusted.gpg keyring" Issue in Ubuntu]
* [https://manpages.ubuntu.com/manpages/xenial/man8/apt-key.8.html apt-key commands list/add/del]
** '''apt-key list''': This command lists the trusted keys that are currently stored in the /etc/apt/trusted.gpg file and the /etc/apt/trusted.gpg.d directory
** '''apt-key add''' [filename]
** '''apt-key del''' [keyid]
== Setup APT Proxy ==
[https://www.howtoforge.com/how-to-setup-apt-proxy-on-ubuntu/ How to Setup APT Proxy on Ubuntu 20.04 LTS]


= E: Could not get lock /var/lib/dpkg/lock =
= E: Could not get lock /var/lib/dpkg/lock =
Line 122: Line 211:


= Difference between dpkg and aptitude/apt-get/gdebi =
= Difference between dpkg and aptitude/apt-get/gdebi =
https://askubuntu.com/questions/309113/what-is-the-difference-between-dpkg-and-aptitude-apt-get
* https://askubuntu.com/questions/309113/what-is-the-difference-between-dpkg-and-aptitude-apt-get
* [https://www.makeuseof.com/apt-vs-dpkg/ What’s the Difference Between APT and dpkg in Ubuntu?] When APT (or its cousin, Apt-get) installs a package, it's actually using '''dpkg''' on the back-end to accomplish that. In that way, '''dpkg''' acts more as an "under the hood" tool for APT's more user-friendly interface.
 
== apt vs. apt-get ==
[https://www.howtogeek.com/791055/apt-vs.-apt-get-whats-the-difference-on-linux/ apt vs. apt-get: What’s the Difference on Linux?]
 
= Some useful apt commands =
* [https://www.cyberciti.biz/faq/ubuntu-lts-debian-linux-apt-command-examples/ 19 Ubuntu / Debian Linux apt Command Examples]
* [https://opensource.com/article/21/6/apt-linux Linux package management with apt]
** Finding software: '''apt search cockpit'''
** Package metadata: '''apt show cockpit'''
** What package provides a file?: '''apt-file search qmake-qt5'''
** What files are included in a package?: '''apt-file list cockpit'''
** Removing an application: '''sudo apt purge apt-file''' & '''sudo apt autoremove'''


= Install a deb file =
= deb file =
== Show deb file information ==
Use '''dpkg -c''' or '''dpkg-deb -c''' commands. The "-c" option stands for "contents".
<pre>
apt download lsof
dpkg -c lsof_4.95.0-1_amd64.deb
 
dpkg-deb -I XXX.deb
 
dpkg-deb -c XXX.deb # list file content
</pre>
 
== Install a deb file (including dependencies): dpkg command ==
The dpkg -i command is lower level and has the following advantages: Direct control (you want to handle dependencies manually) and offline installation. On the other hand, the apt install command is higher level and has these advantages: Dependence resolution and repository access.
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
sudo apt install ./application.deb
# OR
# dpkg gives more clear about the error message
# dpkg gives more clear about the error message
sudo dpkg -i application.deb
sudo dpkg -i application.deb
# Or
sudo apt install application.deb
</syntaxhighlight>
</syntaxhighlight>
Note:


However, installing from a .deb file through dpkg does not resolve dependency issues the same way installation through apt will. See [https://askubuntu.com/questions/784935/unable-to-install-r-studio here].  
1. Remember to add "./" before the package name when we use the "apt install" command because "apt install" expect a package name or a full path to a deb file ("application.deb" is neither a package name or a full path).
 
2. However, installing from a .deb file through dpkg does not resolve dependency issues the same way installation through apt will. See [https://askubuntu.com/questions/784935/unable-to-install-r-studio here] and [https://linuxhint.com/install-dpkg-dependencies-automatically/ How to let dpkg Install Dependencies Automatically]. So you should run '''sudo apt-get install -f''' to fix and install dependencies. After that, run the '''sudo dpkg -i application.deb''' again.  


So you should run sudo apt-get install -f to fix and complete the installation if any errors were encountered by dpkg.
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
sudo apt install -f dep1.deb dep2.deb dep3.deb
sudo apt install -f dep1.deb dep2.deb # NOT apt -f install XXX.deb
</syntaxhighlight>
</syntaxhighlight>


A better way to install a deb file is using the '''gdebi''' tool.
3. The advantage of using apt over dpkg is that apt will automatically resolve and install any dependencies required by the .deb package, whereas with dpkg you would have to manually resolve them using sudo apt-get install -f.


= Remove deb packages =
4. Another way to install a deb file is using the '''gdebi''' tool.
 
== How to install .deb package with double click ==
Right click a deb file and choose "Software Install".
 
But if it is an upgrade of an existing software, it can only let you remove it and can't upgrade.
 
== Remove deb packages ==
See the [http://manpages.ubuntu.com/manpages/trusty/man1/dpkg.1.html man page].
See the [http://manpages.ubuntu.com/manpages/trusty/man1/dpkg.1.html man page].
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
Line 164: Line 288:
See http://askubuntu.com/questions/444240/ubuntu-updates-blocked-apt-get
See http://askubuntu.com/questions/444240/ubuntu-updates-blocked-apt-get
<pre>
<pre>
sudo rm -f /etc/apt/sources.list.d/*
sudo rm -f /etc/apt/sources.list.d/*   # PPA list


sudo dpkg -i /var/cache/apt/archives/*.deb
sudo dpkg -i /var/cache/apt/archives/*.deb
Line 172: Line 296:


= apt-cache =
= apt-cache =
[http://itsfoss.com/apt-cache-command How to Use apt-cache Command in Debian, Ubuntu and Other Linux Distributions]
== /var/lib/apt/lists ==
== /var/lib/apt/lists ==
https://unix.stackexchange.com/questions/217369/clear-apt-get-list
https://unix.stackexchange.com/questions/217369/clear-apt-get-list
Line 180: Line 306:
</syntaxhighlight>
</syntaxhighlight>


== Show package information ==
Examples:
<pre>
$ apt list | wc -l
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
76113
 
$ apt list --installed  | wc -l
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
2816
 
$ apt-cache pkgnames | wc -l
71223
</pre>
 
== Show package information and list all versions ==
Note the <package> does not have to be installed.
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
apt-cache show <package_name>
apt-cache show <package_name>
apt-cache show <package_name> | grep Version
apt-cache show <package_name> | grep Version
</syntaxhighlight>
</syntaxhighlight>
What is the difference of '''apt show ''' and '''apt-cache show'''?


== How can I see all versions of a package that are available ==
== How can I see all versions of a package that are available ==
Line 197: Line 339:
apt-cache policy <package_name>
apt-cache policy <package_name>
</syntaxhighlight>
</syntaxhighlight>
For example, I don't have apache2 installed.
<pre>
$ apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.4.41-4ubuntu3.11
  Version table:
    2.4.41-4ubuntu3.11 500
        500 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
    2.4.41-4ubuntu3.10 500
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
    2.4.41-4ubuntu3 500
        500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
</pre>


== Check dependencies for specific packages ==
== Check dependencies for specific packages ==
[https://www.makeuseof.com/how-to-check-package-dependencies-in-ubuntu/ How to List Dependencies of a Package in Ubuntu]
<syntaxhighlight lang='bash'>
$ apt depends r-base # or apt-cache depends r-base
r-base
  Depends: r-base-core (>= 3.6.3-1bionic)
  Depends: r-recommended (= 3.6.3-1bionic)
  Recommends: r-base-html
  Recommends: r-doc-html
  Suggests: elpa-ess
|Suggests: r-doc-info
  Suggests: r-doc-pdf
$ apt-cache showpkg <package_name>
</syntaxhighlight>
== Show the recommended packages ==
Consider the example of the "r-base" package,
<pre>
apt-cache show r-base
# OR
apt show r-base
</pre>
== Get a list of packages installed by the command ==
Consider the example of the calling "sudo apt-get build-dep r-base" package,
{{Pre}}
dpkg --get-selections > installed_packages_before.txt
sudo apt-get build-dep r-base
dpkg --get-selections > installed_packages_after.txt
diff installed_packages_before.txt installed_packages_after.txt > installed_by_build-dep.txt
</pre>
== Checking dependencies and reverse dependencies with apt-rdepends ==
[https://itsfoss.com/check-dependencies-package-ubuntu/ How to Check Dependencies of a Package in Ubuntu/Debian-based Linux Distributions]
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
apt-cache showpkg <package_name>
$ sudo apt install apt-rdepends
$ apt-rdepends -r inxi
Reading package lists... Done
Building dependency tree     
Reading state information... Done
inxi
  Reverse Depends: forensics-extra (2.14)
forensics-extra
  Reverse Depends: forensics-full (2.14)
forensics-full
 
$ apt-rdepends -r sysbench
Reading package lists... Done
Building dependency tree     
Reading state information... Done
sysbench
  Reverse Depends: hardinfo (0.6~alpha~git20211203~focal)
hardinfo
$ apt-cache depends  hardinfo
hardinfo
  Depends: pciutils
    pciutils:i386
  Depends: zlib1g-dev
  Depends: dmidecode
    dmidecode:i386
  Depends: fwupd
  Depends: lm-sensors
  Depends: sysbench
  Depends: usbutils
    usbutils:i386
  Depends: libc6
  Depends: libcairo2
  Depends: libgdk-pixbuf2.0-0
  Depends: libglib2.0-0
  Depends: libgtk-3-0
  Depends: libjson-glib-1.0-0
  Depends: libpango-1.0-0
  Depends: libpangocairo-1.0-0
  Depends: libsoup2.4-1
  Depends: libx11-6
  Suggests: mesa-utils
</syntaxhighlight>
</syntaxhighlight>


Line 217: Line 450:


Note that --install-suggests will be recursive. It may install ''a lot'' of packages.
Note that --install-suggests will be recursive. It may install ''a lot'' of packages.
= Download debs and then upgrade =
<pre>
sudo apt-get upgrade --download-only
sudo apt-get upgrade
# sudo apt-get upgrade --no-download
</pre>


= Upgrade a package =
= Upgrade a package =
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
apt-get install <package_name>
apt-get install <package_name>
sudo apt --only-upgrade install package_name
# It won’t install the given package if it is not already installed
</syntaxhighlight>
</syntaxhighlight>


Line 230: Line 473:


= Remove a package =
= Remove a package =
[https://www.cyberciti.biz/faq/linux-uninstall-package-software-using-the-cli/ Linux uninstall package / software using the CLI]
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
sudo apt-get remove <package_name>
sudo apt-get remove <package_name>
Line 238: Line 483:
sudo apt-get purge <package_name>
sudo apt-get purge <package_name>
sudo apt-get remove --purge <package_name>
sudo apt-get remove --purge <package_name>
# examples
sudo apt remove --purge libreoffice
sudo apt remove --purge thunderbird
</syntaxhighlight>
</syntaxhighlight>
[https://www.linuxfordevices.com/tutorials/ubuntu/uninstalling-packages-with-apt#Whats-the-difference-between-remove-and-purge What’s the difference between ‘remove‘ and ‘purge‘ ?] The primary difference being ‘remove‘ and ‘purge‘ is that ‘remove‘ only gets rid of the package leaving any configuration files untouched. Whereas ‘purge‘ not only removes the package but also removes all configuration files OUTSIDE THE HOME DIRECTORY.


= Rollback an apt-get upgrade =
= Rollback an apt-get upgrade =
Line 297: Line 548:
sudo apt-get check
sudo apt-get check
</syntaxhighlight>
</syntaxhighlight>
= Fix broken packages =
* [https://www.howtogeek.com/how-to-fix-broken-packages-on-linux/ How to Fix Broken Packages on Linux]
* [https://www.makeuseof.com/how-to-find-and-fix-broken-packages-on-linux/ How to Find and Fix Broken Packages on Linux]
<pre>
sudo apt --fix-missing update
sudo apt update
sudo apt install -f
</pre>
== Not all updates can be installed: partial upgrade ==
[https://itectec.com/ubuntu/ubuntu-not-all-updates-can-be-installed-partial-upgrade/ Not all updates can be installed: partial upgrade], [https://askubuntu.com/questions/1334791/not-all-updates-can-be-installed-in-software-updater Not all updates can be installed in software updater]
<pre>
$ sudo update-manager
$ sudo apt-get install -f
</pre>
= Search a package =
* [https://itsfoss.com/install-zlib-ubuntu/ How to Install Zlib on Ubuntu Linux]. Use the '''apt search''' command
* [https://itsfoss.com/apt-search-command/ Using ‘apt search’ and ‘apt show’ Commands to Search and Find Details of Packages in Ubuntu]


= Search missing package's full name =
= Search missing package's full name =
Line 392: Line 663:
= List of installed packages =
= List of installed packages =
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
dpkg --get-selections
apt list --installed | wc -l
# Or using [https://wiki.debian.org/ListInstalledPackages dpkg-query] utility.
# Or using [https://wiki.debian.org/ListInstalledPackages dpkg-query] utility.
dpkg-query -l
dpkg-query -l
dpkg --get-selections
</syntaxhighlight>
</syntaxhighlight>


Line 417: Line 690:
zgrep "upgrade " /var/log/dpkg.log.2.gz
zgrep "upgrade " /var/log/dpkg.log.2.gz
</syntaxhighlight>
</syntaxhighlight>
Another location is '''/var/log/apt/history*'''
Difference of /var/log/apt/history.log and /var/log/dpkg.log
* /var/log/apt/history.log: This log records high-level package management activities performed through the apt command.
* /var/log/dpkg.log: This log captures lower-level details of package management actions performed by the dpkg tool


= Install a list of packages =
= Install a list of packages =
Line 485: Line 764:
[http://www.ubuntugeek.com/cleaning-up-a-ubuntu-gnulinux-system-updated-with-ubuntu-14-10-and-more-tools-added.html ubuntugeek.com]
[http://www.ubuntugeek.com/cleaning-up-a-ubuntu-gnulinux-system-updated-with-ubuntu-14-10-and-more-tools-added.html ubuntugeek.com]


= unmet dependencies after adding a PPA & apt --fix-broken =
= PPA =
[https://linuxhint.com/ppa_repositories_ubuntu/ A Guide to Using PPA Repositiories in Ubuntu]
 
== unmet dependencies when trying to install okular ==
This happened on Ubuntu 20.04
<pre>
The following packages have unmet dependencies:
okular : Depends: libokular5core9 (= 4:19.12.3-2ubuntu1) but it is not going to be installed
          Depends: phonon4qt5 but it is not going to be installed
          Recommends: okular-extra-backends but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
</pre>
'''GNOME software''' can install Okular without any issue.
 
== unmet dependencies after adding a PPA & apt --fix-broken ==
http://askubuntu.com/questions/140246/how-do-i-resolve-unmet-dependencies-after-adding-a-ppa
http://askubuntu.com/questions/140246/how-do-i-resolve-unmet-dependencies-after-adding-a-ppa


Line 531: Line 824:
sudo apt-get upgrade
sudo apt-get upgrade
</syntaxhighlight>
</syntaxhighlight>
Another case: I installed R 4.0.0 using ''sudo add-apt-repository --yes ”ppa:edd/r-4.0” '' by following [http://dirk.eddelbuettel.com/papers/r4_upgrade_to_r400.pdf#page=9 this], then I remove and install the [https://cran.rstudio.com/bin/linux/ubuntu/README.html official one]. The above 3 commands does not help. (Ubuntu 18.04).
<pre>
The following packages have unmet dependencies:
r-base : Depends: r-recommended (= 4.0.0-1.1804.0) but 4.0.0-1.1804.1 is to be installed
E: Unable to correct problems, you have held broken packages.
</pre>
The solution is to use '''Aptitude''' command. See [https://appuals.com/fix-unmet-dependencies-error-ubuntu/ How to Fix Unmet Dependencies Error on Ubuntu]
<pre>
$ sudo aptitude install r-base                                  9:55:45
The following NEW packages will be installed:
  r-base{b}
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 43.3 kB of archives. After unpacking 62.5 kB will be used.
The following packages have unmet dependencies:
r-base : Depends: r-recommended (= 4.0.0-1.1804.0) but 4.0.0-1.1804.1 is installed
The following actions will resolve these dependencies:
    Keep the following packages at their current version:
1)    r-base [Not Installed]                           
Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:
    Downgrade the following packages:                                     
1)    r-recommended [4.0.0-1.1804.1 (now) -> 4.0.0-1.1804.0 (bionic-cran40)]
Accept this solution? [Y/n/q/?]
The following packages will be DOWNGRADED:
  r-recommended
The following NEW packages will be installed:
  r-base
0 packages upgraded, 1 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.
</pre>


= Fix broken Ubuntu =
= Fix broken Ubuntu =
Line 547: Line 878:
$ sudo reboot
$ sudo reboot
</syntaxhighlight>
</syntaxhighlight>
= Convert packages =
[https://www.makeuseof.com/how-to-convert-between-linux-packages-using-alien/ How to Convert Between Linux Packages Using Alien]

Latest revision as of 12:45, 1 November 2024

Package maintenance

Security of deb packages

How DEB Packages Are Backdoored and How to Detect It

wajig: Simplyfying Debian Administration

GNOME software

nala

Package repository and /etc/apt/sources.list

echo "new line of text" | sudo tee -a /etc/apt/sources.list
# OR
# use 'add-apt-repository' command 
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 886DDD89
sudo add-apt-repository "deb http://deb.torproject.org/torproject.org $(lsb_release -s -c) main"
sudo apt-get update
sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list'
# Or the following if the OS is Ubuntu 
# (other derived distributions like Linux Mint do not count)
# because $(lsb_release -s -c) returns the CodeName which diffs from each Linux distributions.
# sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu $(lsb_release -s -c)/" >> /etc/apt/sources.list' 

gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install r-base

sources.list.d

This directory has more contents than the /etc/apt/sources.list file. For example, on my Mint 17.2

$ cat /etc/apt/sources.list
#deb cdrom:[Linux Mint 17.2 _Rafaela_ - Release amd64 20150627]/ trusty contrib main non-free
deb http://download.virtualbox.org/virtualbox/debian trusty contrib
$ ls /etc/apt/sources.list.d
additional-repositories.list  google-chrome.list                   shutter-ppa-trusty.list
docker.list                   mc3man-mpv-tests-trusty.list         stebbins-handbrake-releases-trusty.list
ekozincew-ppa-trusty.list     official-package-repositories.list   webupd8team-java-trusty.list
getdeb.list                   openshot_developers-ppa-trusty.list  wine-wine-builds-trusty.list

See an example of how to use it: https://apt.syncthing.net/

# Add the release PGP keys:
curl -s https://syncthing.net/release-key.txt | sudo apt-key add -

# Add the "stable" channel to your APT sources:
echo "deb https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list

# Update and install syncthing:
sudo apt-get update
sudo apt-get install syncthing

Remove a repository

sudo add-apt-repository --remove ppa:<ppa_name>
sudo add-apt-repository -r ppa:<ppa_name>

GPG

A Practical Guide to GPG.

$ sudo apt update  # today is 10/22/2020

W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/ InRelease: The following signatures were invalid: EXPKEYSIG 51716619E084DAB9 Michael Rutter <[email protected]>
...

How to add a GPG key to the apt sources keyring?

wget -qO - https://deb.opera.com/archive.key | sudo apt-key add -

$ apt-key list
/etc/apt/trusted.gpg
--------------------
...
pub   rsa2048 2010-10-19 [SCA] [expired: 2020-10-16]
      E298 A3A8 25C0 D65D FD57  CBB6 5171 6619 E084 DAB9
uid           [ expired] Michael Rutter <[email protected]>
...

The solution is to run the sudo apt-key again.

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

$ apt-key list
pub   rsa2048 2010-10-19 [SCA] [expires: 2027-09-30]
      E298 A3A8 25C0 D65D FD57  CBB6 5171 6619 E084 DAB9
uid           [ unknown] Michael Rutter <[email protected]>
sub   rsa2048 2010-10-19 [E] [expires: 2027-09-30]

An example for installing R software on Ubuntu

sudo apt update -qq
sudo apt install --no-install-recommends software-properties-common dirmngr

wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# -qO- will print to standard output screen
# If we use "-q", it will save to the disk

gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc 
# pub   rsa2048 2010-10-19 [SCA] [expires: 2027-09-30]
#       E298A3A825C0D65DFD57CBB651716619E084DAB9         <--- fingerprint
# uid                      Michael Rutter <[email protected]>
# sub   rsa2048 2010-10-19 [E] [expires: 2027-09-30]

sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"

More info:

Setup APT Proxy

How to Setup APT Proxy on Ubuntu 20.04 LTS

E: Could not get lock /var/lib/dpkg/lock

I get the above message when I run sudo apt-get update on a virtual machine that I have not used for a long time (on Ubuntu click 'Show Applications' and type Logs). Many people also reported this problem. The following shows the reason why I got the error. My case seems to be related to the process apt.systemd.daily. Read the comment by Kjetil S from the link in Solution 1 below. One easy solution I did is to reboot the machine.

brb@ubuntu1804:~/Downloads$ sudo apt install mupdf
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
brb@ubuntu1804:~/Downloads$ ps aux | grep -i apt
root      1327  0.0  0.0   4628   772 ?        Ss   09:26   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily update
root      1371  0.0  0.0   4628  1780 ?        S    09:26   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held update
_apt      3902  3.0  0.2  88932  8636 ?        S    09:29   0:05 /usr/lib/apt/methods/http
brb       4516  0.0  0.0  21536  1032 pts/0    S+   09:32   0:00 grep --color=auto -i apt

Solution 1:

Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?.

I can reproduce the error from a clean boot. The most possible explanation is the answer from poolie:

the command-line apt overlaps with update-manager automatically polling. So if you try again in a few minutes that should fix it.

From my experience, after I wait about 10 minutes, ps -A | grep apt won't show anything.

Solution 2:

Fix “Unable to lock the administration directory (/var/lib/dpkg/)” in Ubuntu

# Method 1: Find and Kill all apt-get or apt Processes
$ ps -A | grep apt
1760 ?    00:00:00 apt.systemd.dai
3489 ?    00:00:00 aptd
$ sudo kill -9 1760
$ sudo kill -9 3489
$ sudo apt-get install keepass2
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

# Method 2: Delete the lock Files
sudo rm /var/lib/apt/lists/lock
# and 
sudo rm /var/lib/dpkg/lock

How To Force APT Package Manager To Use IPv4 In Ubuntu 16.04

https://www.ostechnix.com/how-to-force-apt-package-manager-to-use-ipv4-in-ubuntu-16-04/

dpkg error: Package is in a very bad inconsistent state

https://askubuntu.com/questions/148715/how-to-fix-package-is-in-a-very-bad-inconsistent-state-error

The following solution works for me (zramswap-enabler in this example).

# Remove the broken package via the following command:
sudo dpkg --remove --force-remove-reinstreq zramswap-enabler

# Install the package again:
sudo apt-get install zramswap-enabler

Difference between dpkg and aptitude/apt-get/gdebi

apt vs. apt-get

apt vs. apt-get: What’s the Difference on Linux?

Some useful apt commands

deb file

Show deb file information

Use dpkg -c or dpkg-deb -c commands. The "-c" option stands for "contents".

apt download lsof
dpkg -c lsof_4.95.0-1_amd64.deb

dpkg-deb -I XXX.deb

dpkg-deb -c XXX.deb # list file content

Install a deb file (including dependencies): dpkg command

The dpkg -i command is lower level and has the following advantages: Direct control (you want to handle dependencies manually) and offline installation. On the other hand, the apt install command is higher level and has these advantages: Dependence resolution and repository access.

sudo apt install ./application.deb
# OR
# dpkg gives more clear about the error message
sudo dpkg -i application.deb

Note:

1. Remember to add "./" before the package name when we use the "apt install" command because "apt install" expect a package name or a full path to a deb file ("application.deb" is neither a package name or a full path).

2. However, installing from a .deb file through dpkg does not resolve dependency issues the same way installation through apt will. See here and How to let dpkg Install Dependencies Automatically. So you should run sudo apt-get install -f to fix and install dependencies. After that, run the sudo dpkg -i application.deb again.

sudo apt install -f dep1.deb dep2.deb # NOT apt -f install XXX.deb

3. The advantage of using apt over dpkg is that apt will automatically resolve and install any dependencies required by the .deb package, whereas with dpkg you would have to manually resolve them using sudo apt-get install -f.

4. Another way to install a deb file is using the gdebi tool.

How to install .deb package with double click

Right click a deb file and choose "Software Install".

But if it is an upgrade of an existing software, it can only let you remove it and can't upgrade.

Remove deb packages

See the man page.

dpkg -l | grep 'tcl'
sudo dpkg -r tcl8.4 # -r means remove/uninstall
sudo dpkg -P tcl8.4 # -P means purge

dpkg -l | grep 'tcl'   (optional)

gdebi: an improvement over dpkg

How does gdebi automatically gets missing dependancies ? Can I use gdebi for all other installations of .deb packages?

sudo apt-get install gdebi-core

# wget newPackage.deb
# sudo gdebi -n newPackage.deb

deb files caches

See http://askubuntu.com/questions/444240/ubuntu-updates-blocked-apt-get

sudo rm -f /etc/apt/sources.list.d/*    # PPA list

sudo dpkg -i /var/cache/apt/archives/*.deb

sudo dpkg --configure -a

apt-cache

How to Use apt-cache Command in Debian, Ubuntu and Other Linux Distributions

/var/lib/apt/lists

https://unix.stackexchange.com/questions/217369/clear-apt-get-list

List all available packages (from repositories)

apt-cache pkgnames # pkgnames is part of the command

Examples:

$ apt list | wc -l
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
76113

$ apt list --installed  | wc -l
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
2816

$ apt-cache pkgnames | wc -l
71223

Show package information and list all versions

Note the <package> does not have to be installed.

apt-cache show <package_name>
apt-cache show <package_name> | grep Version

What is the difference of apt show and apt-cache show?

How can I see all versions of a package that are available

We can use the show or madison parameter in apt-cache. For example,

apt-cache show <package_name> | grep Version
apt-cache madison <package_name> # wide output, include repository URLs

Show the candidcate version and whether any version is installed

apt-cache policy <package_name>

For example, I don't have apache2 installed.

$ apt-cache policy apache2
apache2:
  Installed: (none)
  Candidate: 2.4.41-4ubuntu3.11
  Version table:
     2.4.41-4ubuntu3.11 500
        500 http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
     2.4.41-4ubuntu3.10 500
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
     2.4.41-4ubuntu3 500
        500 http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages

Check dependencies for specific packages

How to List Dependencies of a Package in Ubuntu

$ apt depends r-base # or apt-cache depends r-base
r-base
  Depends: r-base-core (>= 3.6.3-1bionic)
  Depends: r-recommended (= 3.6.3-1bionic)
  Recommends: r-base-html
  Recommends: r-doc-html
  Suggests: elpa-ess
 |Suggests: r-doc-info
  Suggests: r-doc-pdf

$ apt-cache showpkg <package_name>

Show the recommended packages

Consider the example of the "r-base" package,

apt-cache show r-base
# OR
apt show r-base

Get a list of packages installed by the command

Consider the example of the calling "sudo apt-get build-dep r-base" package,

dpkg --get-selections > installed_packages_before.txt
sudo apt-get build-dep r-base
dpkg --get-selections > installed_packages_after.txt
diff installed_packages_before.txt installed_packages_after.txt > installed_by_build-dep.txt

Checking dependencies and reverse dependencies with apt-rdepends

How to Check Dependencies of a Package in Ubuntu/Debian-based Linux Distributions

$ sudo apt install apt-rdepends
$ apt-rdepends -r inxi
Reading package lists... Done
Building dependency tree       
Reading state information... Done
inxi
  Reverse Depends: forensics-extra (2.14)
forensics-extra
  Reverse Depends: forensics-full (2.14)
forensics-full

$ apt-rdepends -r sysbench
Reading package lists... Done
Building dependency tree       
Reading state information... Done
sysbench
  Reverse Depends: hardinfo (0.6~alpha~git20211203~focal)
hardinfo
$ apt-cache depends  hardinfo
hardinfo
  Depends: pciutils
    pciutils:i386
  Depends: zlib1g-dev
  Depends: dmidecode
    dmidecode:i386
  Depends: fwupd
  Depends: lm-sensors
  Depends: sysbench
  Depends: usbutils
    usbutils:i386
  Depends: libc6
  Depends: libcairo2
  Depends: libgdk-pixbuf2.0-0
  Depends: libglib2.0-0
  Depends: libgtk-3-0
  Depends: libjson-glib-1.0-0
  Depends: libpango-1.0-0
  Depends: libpangocairo-1.0-0
  Depends: libsoup2.4-1
  Depends: libx11-6
  Suggests: mesa-utils

List racing games package (kind of search packages by key words)

apt-cache search racing game
apt-cache search vsftpd

depends, recommends and suggests

How to install suggested packages in apt-get

By default, apt-get installs recommended packages.

Your option --install-suggests adds in the suggested packages and their suggested dependencies.

Note that --install-suggests will be recursive. It may install a lot of packages.

Download debs and then upgrade

sudo apt-get upgrade --download-only
sudo apt-get upgrade
# sudo apt-get upgrade --no-download

Upgrade a package

apt-get install <package_name>

sudo apt --only-upgrade install package_name
# It won’t install the given package if it is not already installed

Install specific version of the package

Use the "=" with the package-name and append desired version.

sudo apt-get install vsftpd=2.3.5-3ubuntu1

Remove a package

Linux uninstall package / software using the CLI

sudo apt-get remove <package_name>

To completely remove a package including their configuration files

sudo apt-get purge <package_name>
sudo apt-get remove --purge <package_name>

# examples
sudo apt remove --purge libreoffice
sudo apt remove --purge thunderbird

What’s the difference between ‘remove‘ and ‘purge‘ ? The primary difference being ‘remove‘ and ‘purge‘ is that ‘remove‘ only gets rid of the package leaving any configuration files untouched. Whereas ‘purge‘ not only removes the package but also removes all configuration files OUTSIDE THE HOME DIRECTORY.

Rollback an apt-get upgrade

http://www.cyberciti.biz/howto/debian-linux/ubuntu-linux-rollback-an-apt-get-upgrade/

Clean up disk space

The clean command is used to free up the disk space by cleaning retrieved .deb files from the local repository.

sudo apt-get clean

Auto clean up apt-get cache

sudo apt-get autoclean

The 'autoclean' command deletes all .deb files from /var/cache/apt/archives to free up disk space.

What is difference between the options "autoclean", "autoremove" and "clean"? From the apt-get man page: autoclean: Like clean, autoclean clears out the local repository of retrieved package files. The difference is that it only removes package files that can no longer be downloaded, and are largely useless. This allows a cache to be maintained over a long period without it growing out of control. The configuration option APT::Clean-Installed will prevent installed packages from being erased if it is set to off.

Download only source code of package

sudo apt-get --download-only source <package_name>

To download and unpack source code of a package

sudo apt-get source <package_name>

To download, unpack and compile a package

sudo apt-get --compile source <package_name>

Download without installing

sudo apt-get download <package_name>

Check change log of package

Note that the change log may not be found.

sudo apt-get changelog <package_name>

Simulate installing packages

$ sudo apt-get -s install packagename

$ sudo apt-get -s build-dep packagename
$ man apt-get

Generally, it is good to build-dep then install package.

Check broken dependencies

sudo apt-get check

Fix broken packages

sudo apt --fix-missing update
sudo apt update
sudo apt install -f

Not all updates can be installed: partial upgrade

Not all updates can be installed: partial upgrade, Not all updates can be installed in software updater

$ sudo update-manager
$ sudo apt-get install -f

Search a package

Search missing package's full name

Use the apt-file command. See this post

At first, install apt-file command and prepare it.

$ sudo apt-get install apt-file
$ sudo apt-file update

To find zlib.h,

$ apt-file search zlib.h

It reports too many result. Let’s narrow down.

$ apt-file search /usr/include/zlib.h
zlib1g-dev: /usr/include/zlib.h

Now you know zlib.h is in zlib1g-dev package.

$ sudo apt-get install zlib1g-dev

Find package information before installing it

Use "-s" option for simulation. No sudo is necessary.

apt-get -s install PACKAGENAME

The output is too much (include other dependences)

A better way is to use aptitude (which is not installed by default in Ubuntu)

aptitude search <package> -F "%c %p %d %V"

For example,

debian@beaglebone:~/qt-4.8.5/bin$ aptitude search  qtcreator -F "%c %p %d %V"
p qtcreator                         lightweight integrated development environme 2.5.0-2       
p qtcreator:armel                   lightweight integrated development environme 2.5.0-2       
p qtcreator-dbg                     debugging symbols for Qt Creator IDE         2.5.0-2       
p qtcreator-dbg:armel               debugging symbols for Qt Creator IDE         2.5.0-2       
p qtcreator-doc                     documentation for Qt Creator IDE             2.5.0-2   

If a package is already installed, we can use the following way to check version number.

apt-show-versions <package>

dpkg Command : View Package Information On Debian/Ubuntu/Mint Systems

dpkg -s r-base

aptitude Command : View Package Information On Debian/Ubuntu/Mint Systems

aptitude show htop

List files in a package

dpkg -L <package_name>

Search installed packages

dpkg -l libgtk* | grep -e '^i'
dpkg -l libpng* | grep -e '^i'
dpkg -l libjpeg* | grep -e '^i'

To search x-org related packages

udooer@udoo:~$ dpkg -l | grep xserver-xorg | awk '{$1=$3=$4=""; print $0}'  # Skip columns 1,3,4
 imx-xserver-xorg-extension-viv-9t6-hdmi   Freescale Xorg server driver extension for HDMI performance
 imx-xserver-xorg-video-viv-9t6   Xorg server driver for imx6, vivante
 xserver-xorg   X.Org X server
 xserver-xorg-core   Xorg X server - core server
 xserver-xorg-dev   Xorg X server - development files
 xserver-xorg-input-all   X.Org X server -- input driver metapackage
 xserver-xorg-input-evdev   X.Org X server -- evdev input driver
 xserver-xorg-input-synaptics   Synaptics TouchPad driver for X.Org server
 xserver-xorg-input-wacom   X.Org X server -- Wacom input driver
 xserver-xorg-video-all   X.Org X server -- output driver metapackage
 xserver-xorg-video-fbdev   X.Org X server -- fbdev display driver
 xserver-xorg-video-modesetting   X.Org X server -- Generic modesetting driver
 xserver-xorg-video-omap   X.Org X server -- OMAP display driver
 xserver-xorg-video-vesa   X.Org X server -- VESA display driver

List of installed packages

apt list --installed | wc -l
# Or using [https://wiki.debian.org/ListInstalledPackages dpkg-query] utility.
dpkg-query -l

dpkg --get-selections

Show A History Of Installed, Upgraded Or Removed Packages

https://www.linuxuprising.com/2019/01/how-to-show-history-of-installed.html?m=1

# recently installed packages, their version number
grep "install " /var/log/dpkg.log

# recently upgraded packages, as well as the old and new package version
grep "upgrade " /var/log/dpkg.log

# recently removed packages
grep "remove " /var/log/dpkg.log

/var/log/dpkg.log contains the package install, update and remove history for the current month. For the previous month, read the /var/log/dpkg.log.1 log file. Want to go back even more in the dpkg history? Use zgrep instead of grep, and read /var/log/dpkg.log.2.gz, /var/log/dpkg.log.3.gz, /var/log/dpkg.log.4.gz and so on (up to 12 months),

grep "install " /var/log/dpkg.log.1

zgrep "upgrade " /var/log/dpkg.log.2.gz

Another location is /var/log/apt/history*

Difference of /var/log/apt/history.log and /var/log/dpkg.log

  • /var/log/apt/history.log: This log records high-level package management activities performed through the apt command.
  • /var/log/dpkg.log: This log captures lower-level details of package management actions performed by the dpkg tool

Install a list of packages

How to get list of installed packages on Ubuntu / Debian Linux

Suppose we want to install all packages currently installed on server 1 onto server 2, we can do that by

# server 1
dpkg --get-selections | grep -v deinstall > mylist.txt
# server 2
sudo dpkg --set-selections < mylist.txt

Show (sort) package size

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n

Check if a library is installed or not (ldconfig)

Use ldconfig -p | grep LIBNAME ('-p' is used to print the list stored in the current cache). For example, to check if libxml is installed or not, then following code will output the number of matches if it was found.

EXIST=`ldconfig -p | grep libxml | wc -l`
if [ $EXIST -ne 0 ]; then echo $EXIST; fi

The following code will search "libQt" and the library version will be shown in the file name.

ldconfig -p | grep libQt
# On Ubuntu 14.04, 16.04:
# libQtGui.so.4 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libQtGui.so.4
# On Ubuntu 17.10, 18.04:
# libQt5Gui.so.5 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5

To install libQtGui.so.4 in Ubuntu 18.04, run the command

sudo apt-get install libqtgui4

See also the ldd command to print all dynamic dependencies of an executable program.

How to uninstall software

http://www.howtogeek.com/229699/how-to-uninstall-software-using-the-command-line-in-linux/

Upgrade software packages

Upgrade all the currently installed software packages on the system

sudo apt-get upgrade

If you want to upgrade, unconcerned of whether software packages will be added or removed to fulfill dependencies, use

sudo apt-get dist-upgrade

List of available (uninstalled) packages

aptitude -F "%p" search "?not(?installed)"

See http://superuser.com/questions/408082/how-do-i-get-a-list-of-available-i-e-uninstalled-packages-in-debian

Check Change Log of Package

sudo apt-get changelog PKGNAME

Clean up/remove packages

ubuntugeek.com

PPA

A Guide to Using PPA Repositiories in Ubuntu

unmet dependencies when trying to install okular

This happened on Ubuntu 20.04

The following packages have unmet dependencies:
 okular : Depends: libokular5core9 (= 4:19.12.3-2ubuntu1) but it is not going to be installed
          Depends: phonon4qt5 but it is not going to be installed
          Recommends: okular-extra-backends but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

GNOME software can install Okular without any issue.

unmet dependencies after adding a PPA & apt --fix-broken

http://askubuntu.com/questions/140246/how-do-i-resolve-unmet-dependencies-after-adding-a-ppa

$ sudo apt-get install libgl1-mesa.dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libgl1-mesa-dev-lts-quantal' for regex 'libgl1-mesa.dev'
Note, selecting 'libgl1-mesa-dev' for regex 'libgl1-mesa.dev'
Note, selecting 'libgl1-mesa-dev-lts-saucy' for regex 'libgl1-mesa.dev'
Note, selecting 'libgl1-mesa-dev-lts-trusty' for regex 'libgl1-mesa.dev'
Note, selecting 'libgl1-mesa-dev-lts-utopic' for regex 'libgl1-mesa.dev'
Note, selecting 'libgl1-mesa-dev-lts-vivid' for regex 'libgl1-mesa.dev'
Note, selecting 'libgl1-mesa-dev-lts-raring' for regex 'libgl1-mesa.dev'
libgl1-mesa-dev is already the newest version.
libgl1-mesa-dev set to manually installed.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libgl1-mesa-dev : Conflicts: libgl-dev
                   Conflicts: libgl1-mesa-dri-dev
 libgl1-mesa-dev-lts-utopic : Depends: mesa-common-dev-lts-utopic (= 10.3.2-0ubuntu1~trusty2) but it is not going to be installed
                              Depends: libgl1-mesa-glx-lts-utopic (= 10.3.2-0ubuntu1~trusty2) but it is not going to be installed
                              Conflicts: libgl-dev
                              Conflicts: libgl1-mesa-dev
                              Conflicts: libgl1-mesa-dri-dev
 libgl1-mesa-dev-lts-vivid : Depends: mesa-common-dev-lts-vivid (= 10.5.9-2ubuntu1~trusty2) but it is not going to be installed
                             Depends: libgl1-mesa-glx-lts-vivid (= 10.5.9-2ubuntu1~trusty2) but it is not going to be installed
                             Conflicts: libgl-dev
                             Conflicts: libgl1-mesa-dev
                             Conflicts: libgl1-mesa-dri-dev
                             Conflicts: xorg-renamed-package-lts-utopic
E: Unable to correct problems, you have held broken packages.

Unmet dependencies when trying to install r-base (Works on Ubuntu 16.04).

sudo apt --fix-broken install
sudo apt-get update
sudo apt-get upgrade

Another case: I installed R 4.0.0 using sudo add-apt-repository --yes ”ppa:edd/r-4.0” by following this, then I remove and install the official one. The above 3 commands does not help. (Ubuntu 18.04).

The following packages have unmet dependencies:
 r-base : Depends: r-recommended (= 4.0.0-1.1804.0) but 4.0.0-1.1804.1 is to be installed
E: Unable to correct problems, you have held broken packages.

The solution is to use Aptitude command. See How to Fix Unmet Dependencies Error on Ubuntu

$ sudo aptitude install r-base                                   9:55:45
The following NEW packages will be installed:
  r-base{b} 
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 43.3 kB of archives. After unpacking 62.5 kB will be used.
The following packages have unmet dependencies:
 r-base : Depends: r-recommended (= 4.0.0-1.1804.0) but 4.0.0-1.1804.1 is installed
The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     r-base [Not Installed]                             



Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

     Downgrade the following packages:                                       
1)     r-recommended [4.0.0-1.1804.1 (now) -> 4.0.0-1.1804.0 (bionic-cran40)]



Accept this solution? [Y/n/q/?] 
The following packages will be DOWNGRADED:
  r-recommended 
The following NEW packages will be installed:
  r-base 
0 packages upgraded, 1 newly installed, 1 downgraded, 0 to remove and 0 not upgraded.

Fix broken Ubuntu

How To Fix Broken Ubuntu OS Without Reinstalling It

$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/lib/dpkg/lock
$ sudo rm /var/lib/dpkg/lock-frontend
$ sudo dpkg --configure -a
$ sudo apt clean
$ sudo apt update --fix-missing
$ sudo apt install -f
$ sudo dpkg --configure -a
$ sudo apt upgrade
$ sudo apt dist-upgrade
$ sudo reboot

Convert packages

How to Convert Between Linux Packages Using Alien