APT

Summary
Advanced Packaging Tool (APT): Debian's high-level package management system, also used by other Linux distributions

Wiki: Advanced Packaging Tool (APT)

APT HOWTO

Configuration
apt configuration folders and files: /etc/apt

apt sources: /etc/pat/sources.list

APT uses /var/lib/apt/lists/* for tracking available packages while dpkg uses /var/lib/dpkg/available. 

Standard Debian:
 * 1) deb file:///cdrom/ sarge main

deb http://mirrors.kernel.org/debian/ stable main deb-src http://mirrors.kernel.org/debian/ stable main

deb http://security.debian.org/ stable/updates main

Installing and Removing Packages
Install package: apt-get install

Reinstall package: apt-get --reinstall install
 * 1) If you somehow damage an installed package, or simply want the files of a package to be reinstalled with the newest version that is
 * 2) available, you can use the --reinstall option like so:

Remove package: apt-get remove

Remove package and purge configuration files: (do before a reinstall if you want default config files back) apt-get --purge remove [package] apt-get purge [package] dpkg --purge [package]   # remove config files from a removed package that wasn't purged

Clear out the local repository of retrieved package files (will likely want to run from time to time to free up disk space): apt-get clean

Package Updates
Retrieve new lists of packages: apt-get update

Upgrade packages: apt-get -u upgrade
 * 1) It's important to always run 'apt-get update' before you try this
 * 2) -u show upgraded packages (otherwise silent)

Simulate upgrade (to see what will change): apt-get -s upgrade

Upgrading to a new release: apt-get -u dist-upgrade

Download upgrade files, but don't install: apt-get -d upgrade apt-get -d dist-upgrade

Upgrade
apt-get clean           # clean cached apt-get update          # update lists

apt-get -s upgrade      # simulate upgrade

apt-get -u update       # upgrade packages (when ready)

apt-get -u dist-upgrade # Install any missing dependencies (for those kept back)

aptitude: aptitude clean aptitude update aptitude dist-upgrade

aptitude 0.4.11.11: aptitude clean aptitude update aptitude safe upgrade aptitude full-upgrade

Searching
Search for a package: apt-cache search [regex]

Determine with package a file came from: dpkg -S [filename_and_path]

Searching with aptitude: apt-cache search ^kernel-image

List installed packages and versions (similar to rpm -qa): dpkg -l | grep [regex]

List files within installed package: dpkg -L [package]

List files within packages (installed and not installed): apt-file update apt-file list [package pattern]
 * 1) Install with 'apt-get install apt-file'
 * 2) Run 'apt-file update' to update the apt-file database first

Search for file within all packages (It works similar to dpkg -S, but including not installed packages): apt-file search [filename]

Show all downloaded packages (including not installed): dpkg -l * dpkg -l \* dpkg -l '*'

Note: Without the star glob, dpkg only lists installed packages.

To search the listing of packages yourself: less /var/lib/dpkg/available

Note: dpkg keeps its record of available packages in /var/lib/dpkg/available. A simpler one-shot command to retrieve and update the available file is dselect update.

Find packages to be updated: apt-show-versions -u apt-show-versions | grep upgradeable
 * 1) apt-get install apt-show-versions

Package Details
Show package details: apt-cache show

Show package dependencies: apt-cache depends

Show package information: apt-cache showpkg

APT maintenance
Clean apt cache: apt-get clean

If an installation breaks in the middle of the process and you find that it's no longer possible to install or remove packages, try running these two commands: apt-get -f install dpkg --configure -a

configures all partially installed packages: dpkg --configure -a dpkg-reconfigure --all

Reconfigure a particular package: dpkg --configure [package] dpkg-reconfigure [package]

Reinstall Config Files
apt-get -o DPkg::options::=--force-confmiss --reinstall install

note: didn't seem to work...

ref:

yum to apt
List available packages: apt-cache search.
 * 1) yum list

Clean cache: apt-cache clean
 * 1) yum clean all

Install package: apt-get install [PACKAGE]
 * 1) yum install [PACAKGE]

Remove package: apt-get remove [PACKAGE]
 * 1) yum remove [PACKAGE]

List package files: dpkg -L [PACKAGE]
 * 1) rpm -qvl [PACKAGE]

List installed packages: dpkg -l
 * 1) rpm -qa

Update Packages: apt-get -u update apt-get -u upgrade apt-get -u dist-upgrade # to include kernel updates
 * 1) yum update

Update package cache: apt-get update
 * 1) yum makecache

Provides: apt-get install apt-file apt-file update apt-file search "/ifconfig"
 * 1) yum provides "*/ifconfig"

dselect
dselect:
 * "dselect is a program that helps users select Debian packages for installation."

TUI: dselect

Update list of available packages (found in /var/lib/dpkg/available): dselect update

aptitude
aptitude:
 * "aptitude is a featureful package manager for Debian GNU/Linux systems, based on the renowned apt package management infrastructure. aptitude provides the functionality of dselect and apt-get, as well as many additional features not found in either program."

Local deb repository
Create a folder somewhere: mkdir /data/debs

May want 'override' file (If you do not want to write an override file, just use /dev/null when calling dpkg-scanpackages): [package] [priority] [section]

Build deb package file: cd /data dpkg-scanpackages debs [override file] | gzip > debs/Packages.gz

Add deb file:/root debs/

Alien - convert .rpm to .deb
To convert an .rpm to .deb...

Summary: install non-native packages with dpkg

Description: Alien allows you to convert LSB, Red Hat, Stampede and Slackware Packages into Debian packages, which can be installed with dpkg. It can also generate packages of any of the other formats. This is a tool only suitable for binary packages.

Install alien: sudo apt-get install alien Convert to .deb file: sudo alien [package].rpm sudo alien --scripts [package].rpm sudo alien --scripts -k [package].rpm
 * 1) Note: use the --scripts parameter to include the scripts.
 * 1) Note: alien will increment the version number. If you want to keep the original version number, you must use the -k switch:

Install .deb file: sudo dpkg -i [package].deb

To skip the dpkg step, convert and install all in one with '-i': sudo alien --scripts -i [package].rpm

More alien info: man alien

References:
 * Convert .rpm to .deb - Ubuntu Forums
 * [RE: convert rpm to deb

apt-mirror
Summary: https://apt-mirror.github.io/

$ sudo apt-get install apt-mirror $ nano /etc/apt/mirror.list $ sudo apt-mirror

Source: https://github.com/apt-mirror/apt-mirror

/etc/apt/mirror.list - Ubuntu 16 and 18: set base_path   /repo/apt-mirror set nthreads    20 set _tilde 0
 * 1) config ##################
 * 2) set base_path    /var/spool/apt-mirror
 * 1) set base_path    /var/spool/apt-mirror
 * 1) set mirror_path  $base_path/mirror
 * 2) set skel_path    $base_path/skel
 * 3) set var_path     $base_path/var
 * 4) set cleanscript $var_path/clean.sh
 * 5) set defaultarch
 * 6) set postmirror_script $var_path/postmirror.sh
 * 7) set run_postmirror 0
 * 1) set run_postmirror 0
 * 1) end config ##############
 * 1) end config ##############


 * 1) Ubuntu 16 ##

deb http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse
 * 1) deb http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse


 * 1) deb-src http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse
 * 2) deb-src http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse
 * 3) deb-src http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse
 * 4) deb-src http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse
 * 5) deb-src http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse


 * 1) Ubuntu 18 ##

deb http://archive.ubuntu.com/ubuntu bionic main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu bionic-security main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse
 * 1) deb http://archive.ubuntu.com/ubuntu bionic-proposed main restricted universe multiverse


 * 1) deb-src http://archive.ubuntu.com/ubuntu bionic main restricted universe multiverse
 * 2) deb-src http://archive.ubuntu.com/ubuntu bionic-security main restricted universe multiverse
 * 3) deb-src http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse
 * 4) deb-src http://archive.ubuntu.com/ubuntu bionic-proposed main restricted universe multiverse
 * 5) deb-src http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse

clean http://archive.ubuntu.com/ubuntu

Uncomment the dev-src sections if you want the source files (takes a ton of space!)

/repo/apt-mirror/var/postmirror.sh:
 * 1) !/bin/bash

echo echo echo echo echo "postmirror: Running clean.sh!"

/repo/apt-mirror/var/clean.sh

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

apt-file find [file] apt-file list [packagename]

apt-file find kwallet.h

apt-file search /usr/lib/tracker/tracker-store apt-file search --regex /tracker-extract$ apt-file search --regex /tracker-miner-fs$

ref:

Could not get lock
Error: 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?

This happens when apt is interrupted during an installation

Solution: (remove lock and resume installation) killall aptitude killall apt-get rm /var/lib/dpkg/lock dpkg --configure -a

The following packages have been kept back
Running 'apt-get upgrade' may show this: The following packages have been kept back: ...

There we can see four packages haven't been upgraded, even though newer packages are available. This is because two new packages were introduced, and these upgrades depend upon it.

To fix this you must run : apt-get dist-upgrade

This will upgrade the packages that have newer versions available, and install any new dependencies which are required to do that.

Source: Some upgrades show packages being kept back

package reportbug upgrade issue
When trying to dist-upgrade Debian to the latest:

Problem: Preparing to replace reportbug 3.8 (using .../reportbug_3.48_all.deb) ... Traceback (most recent call last): File "/usr/bin/pycentral", line 1891, in ? main File "/usr/bin/pycentral", line 1885, in main rv = action.run(global_options) File "/usr/bin/pycentral", line 1296, in run runtimes = get_installed_runtimes File "/usr/bin/pycentral", line 210, in get_installed_runtimes default_version = pyversions.default_version(version_only=True) File "/usr/share/pycentral-data/pyversions.py", line 163, in default_version raise ValueError, "/usr/bin/python does not match the python default version. It must be reset to point to %s" % debian_default ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.4 dpkg: error processing /var/cache/apt/archives/reportbug_3.48_all.deb (--unpack): subprocess pre-installation script returned error exit status 1 Errors were encountered while processing: /var/cache/apt/archives/reportbug_3.48_all.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

Solution: dpkg -r --force all python-newt python-central apt-get -f install apt-get dist-upgrade

Work Arounds
apt-get -f install

trying to overwrite [file] which is also in package [package]
Preparing to replace debianutils 2.8.4 (using …/debianutils_2.23.1_i386.deb) … Unpacking replacement debianutils … dpkg: error processing /var/cache/apt/archives/debianutils_2.23.1_i386.deb (--unpack): trying to overwrite `/usr/sbin/add-shell’, which is also in package passwd Errors were encountered while processing: /var/cache/apt/archives/debianutils_2.23.1_i386.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

Solution: dpkg -r --force all passwd apt-get -f install

Generic Solution: dpkg -r --force all [package] apt-get -f install

Source:

Install these packages without verification?
try...

Solution: apt-get clean ; apt-get update

# or

apt-get install debian-keyring debian-archive-keyring

See: SecureApt - Debian Wiki

This installation run will require temporarily removing the essential package
Problem on 'apt-get -u dist-upgrade': E: This installation run will require temporarily removing the essential package sysvinit due to a Conflicts/Pre-Depends loop. This is often bad, but if you really want to do it, activate the APT::Force-LoopBreak option. E: Internal Error, Could not early remove sysvinit

Cause:

Solution:


 * Option #1:

Remove the problem package and run upgrade again. apt-get remove [package]

WARNING: This will break things that need to be manually repaired

Source: How to solve apt-get upgrade problem - Linux / UNIX Forum


 * Option #2:

Enable the Force-LoopBreak option: apt-get -o APT::Force-LoopBreak=yes dist-upgrade

WARNING: This will break things that need to be manually repaired

Source: DEBIAN APT : Force Loop Break - NickNack's personal blog

Could not open lock file
Error: E: Could not open lock file /var/cache/apt/archives/lock - open (2 No such file or directory) E: Unable to lock the download directory

You deleted the /var/cache/apt/archives folder, didn't you? Recreate the folder, and the 'partial' folder as well.

Solution: mkdir -p /var/cache/apt/archives/partial

readlink: invalid option
Error: Preparing to replace libc6 2.3.2.ds1-11 (using .../libc6_2.7-18lenny4_i386.deb) ... Checking for services that may need to be restarted... Checking init scripts... readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] readlink: invalid option -- e usage: readlink [-n] [-f] symlink [...] WARNING: POSIX threads library NPTL requires kernel version 2.6.8 or later. If you use a kernel 2.4, please upgrade it before installing glibc.

The installation of a 2.6 kernel _could_ ask you to install a new libc first, this is NOT a bug, and should *NOT* be reported. In that case, please add etch sources to your /etc/apt/sources.list and run: apt-get install -t etch linux-image-2.6 Then reboot into this new kernel, and proceed with your upgrade dpkg: error processing /var/cache/apt/archives/libc6_2.7-18lenny4_i386.deb (--unpack): subprocess pre-installation script returned error exit status 1 Errors were encountered while processing: /var/cache/apt/archives/libc6_2.7-18lenny4_i386.deb E: Sub-process /usr/bin/dpkg returned an error code (1)

Solution:

I had this problem too and it is because Debian have moved the packages for sarge to another site (Archive).

I have written a new /etc/apt/sources.list that fixes this. Simply remove the current entries from /etc/apt/sources.list and replace them with this...

deb http://archive.debian.org/debian sarge main contrib non-free

deb http://archive.debian.org/debian-non-US oldstable/non-US main contrib non-free deb-src http://archive.debian.org/debian-non-US oldstable/non-US main contrib non-free

deb http://archive.debian.org/debian-security sarge/updates main contrib non-free deb-src http://archive.debian.org/debian-security sarge/updates main contrib non-free

Source: [http://forums.xbox-scene.com/index.php?showtopic=680973 Installed Xebian 1.1.4, Now I Can't Upgrade Anything? - Scenyx Entertainment Community]

no public key available
Error: $ apt-get update ... Reading package lists... Done W: There is no public key available for the following key IDs: B5D0C804ADB11277 W: You may want to run apt-get update to correct these problems

Solution: apt-key update

If that doesn't work:
 * 1) gpg --keyserver wwwkeys.eu.pgp.net --recv-keys [MISSING_KEY_ID]
 * 2) apt-key add /root/.gnupg/pubring.gpg
 * 3) apt-get update

Source: Small Tip: How to fix “There are no public key available for the following key IDs” Error in Debian « Alexey Kovyrin's Blog

W: Failed to fetch Packages.gz - Not Found
Error: Err http://security.ubuntu.com karmic-security/main Packages 404 Not Found [IP: 91.189.91.14 80] W: Failed to fetch Packages.gz - Not Found E: Some index files failed to download, they have been ignored, or old ones used instead.

"If you want to continue using an outdated release then edit /etc/apt/sources.list and change archive.ubuntu.com to old-releases.ubuntu.com"

sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

I had to change "us.archive" to "old-releases".

References:
 * How to install software or upgrade from old unsupported release? - Ask Ubuntu - http://askubuntu.com/questions/91815/how-to-install-software-or-upgrade-from-old-unsupported-release
 * EOLUpgrades - Community Ubuntu Documentation - https://help.ubuntu.com/community/EOLUpgrades/

Old Release - Failed to fetch
Once support is up for the version of Ubuntu you are using the repository is moved to another server and will no longer be available on the standard  http://archive.ubuntu.com/ubuntu/dist/ location.

The easiest solution is to upgrade: apt-get dist-upgrade

An alternative solution is to point to the moved servers. Run this command below on your server and it will replace all of the archive.ubuntu.com  and  security.ubuntu.com package repository URLs with  old-releases.ubuntu.com sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list apt-get update

https://smyl.es/how-to-fix-ubuntudebian-apt-get-404-not-found-package-repository-errors-saucy-raring-quantal-oneiric-natty/