APT: Difference between revisions
Line 46: | Line 46: | ||
Clear out the local repository of retrieved package files (will likely want to run from time to time to free up disk space): | 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 | apt-get clean | ||
=== See Package Versions === | |||
See what versions are available of a package to you: <ref>https://askubuntu.com/questions/916598/how-to-install-a-package-greater-than-or-equal-to-a-particular-version</ref> | |||
apt policy PACKAGE | |||
=== Install Package by Version === | |||
Install Package by Version: <ref>https://askubuntu.com/questions/916598/how-to-install-a-package-greater-than-or-equal-to-a-particular-version</ref> | |||
sudo apt install PACAKGE=VERSION | |||
=== Install Package Less Than Version with Satisfy === | |||
Install Package Version with Satisfy <ref>https://unix.stackexchange.com/questions/578460/specify-apt-get-a-minimum-version-to-be-installed</ref> <ref>https://askubuntu.com/questions/916598/how-to-install-a-package-greater-than-or-equal-to-a-particular-version</ref> <ref>https://askubuntu.com/questions/916598/how-to-install-a-package-greater-than-or-equal-to-a-particular-version</ref> | |||
sudo apt-get satisfy "foo (>= 1.0), bar (>= 2.0)" | |||
sudo apt satisfy "python3 (>= 3.9), python3-dev (>= 3.9)" | |||
=== Package Updates === | === Package Updates === |
Latest revision as of 20:54, 25 October 2024
Summary
Advanced Packaging Tool (APT): Debian's high-level package management system, also used by other Linux distributions
Wiki: Advanced Packaging Tool (APT)
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. [1]
Standard Debian:
#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
Commands
Installing and Removing Packages
Install package:
apt-get install <package>
Reinstall package:
# If you somehow damage an installed package, or simply want the files of a package to be reinstalled with the newest version that is # available, you can use the --reinstall option like so: apt-get --reinstall install <package>
Remove package:
apt-get remove <package>
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
See Package Versions
See what versions are available of a package to you: [1]
apt policy PACKAGE
Install Package by Version
Install Package by Version: [2]
sudo apt install PACAKGE=VERSION
Install Package Less Than Version with Satisfy
Install Package Version with Satisfy [3] [4] [5]
sudo apt-get satisfy "foo (>= 1.0), bar (>= 2.0)"
sudo apt satisfy "python3 (>= 3.9), python3-dev (>= 3.9)"
Package Updates
Retrieve new lists of packages:
apt-get update
Upgrade packages:
# It's important to always run 'apt-get update' before you try this # -u show upgraded packages (otherwise silent) apt-get -u upgrade
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):
# Install with 'apt-get install apt-file' # Run 'apt-file update' to update the apt-file database first apt-file update apt-file list [package pattern]
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): [2]
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-get install apt-show-versions apt-show-versions -u apt-show-versions | grep upgradeable
Find Package that Provides File
-S, --search filename-search-pattern... Search for a filename from installed packages.
$ dpkg -S /bin/ls coreutils: /bin/ls
ref: [3]
Find Package that Provides File with apt-file
sudo apt-get install apt-file apt-file update
$ apt-file find kwallet.h kdelibs5-dev: /usr/include/kwallet.h libkf5wallet-dev: /usr/include/KF5/KWallet/kwallet.h
Ref: [4]
List Files in Package with dpkg-query
For packages installed:
dpkg-query -L <package>
# dpkg-query -L wget /. /etc /usr/bin/wget ...
Ref: [5]
List Files in Package with apt-file
For packages installed or not installed:
apt-file list <package>
# apt-file list wget wget: /etc/wgetrc wget: /usr/bin/wget ...
Ref: [6]
List Package Dependencies
What packages will this package also install:
apt-cache depends <package>
# apt-cache depends wget wget Depends: libc6 Depends: libidn2-0 ...
Also listed in details of `showpkg`:
apt-cache showpkg <package>
List Package Reverse Dependencies
What packages will install this package as a dependency:
apt-cache rdepends <package>
# apt-cache rdepends wget wget Reverse Depends: |usbutils ubuntu-standard virtualbox-ext-pack ...
Also listed in details of `showpkg`:
apt-cache showpkg <package>
Package Details
Show package details:
apt-cache show <package>
Show package dependencies:
apt-cache depends <package>
Show package information:
apt-cache showpkg <package>
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 <package>
note: didn't seem to work...
ref: [7]
yum to apt
List available packages:
# yum list apt-cache search .
Clean cache:
# yum clean all apt-cache clean
Install package:
# yum install [PACAKGE] apt-get install [PACKAGE]
Remove package:
# yum remove [PACKAGE] apt-get remove [PACKAGE]
List package files:
# rpm -qvl [PACKAGE] dpkg -L [PACKAGE]
List installed packages:
# rpm -qa dpkg -l
Update Packages:
# yum update apt-get -u update apt-get -u upgrade apt-get -u dist-upgrade # to include kernel updates
Update package cache:
# yum makecache apt-get update
Provides:
# yum provides "*/ifconfig" apt-get install apt-file apt-file update apt-file search "/ifconfig"
front ends
dselect
dselect:
- "dselect is a program that helps users select Debian packages for installation." [8]
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." [9]
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/
Repository Structure
See apt/repository
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 # Note: use the --scripts parameter to include the scripts. sudo alien --scripts [package].rpm # Note: alien will increment the version number. If you want to keep the original version number, you must use the -k switch: sudo alien --scripts -k [package].rpm
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:
apt-mirror
See 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:
############# config ################## # # set base_path /var/spool/apt-mirror set base_path /repo/apt-mirror # # set mirror_path $base_path/mirror # set skel_path $base_path/skel # set var_path $base_path/var # set cleanscript $var_path/clean.sh # set defaultarch <running host architecture> # set postmirror_script $var_path/postmirror.sh # set run_postmirror 0 set nthreads 20 set _tilde 0 # ############# end config ############## ## 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-proposed main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse ##deb-src http://archive.ubuntu.com/ubuntu xenial-proposed main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse ## 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-proposed main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu bionic-backports main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu bionic main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu bionic-security main restricted universe multiverse #deb-src http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe multiverse ##deb-src http://archive.ubuntu.com/ubuntu bionic-proposed main restricted universe multiverse #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:
#!/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: [10]
Mark and Hold Package
Don't allow kernel to be updated
Hold a package:
sudo apt-mark hold <package-name>
Remove the hold:
sudo apt-mark unhold <package-name>
Show all packages on hold:
sudo apt-mark showhold
ref: [11]
Show Available Package Versions With Madison
To show available versions of a package:
apt-cache madison [package]
Sample:
# apt-cache madison git git | 1:2.25.1-1ubuntu3.5 | http://us.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages git | 1:2.25.1-1ubuntu3.5 | http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages git | 1:2.25.1-1ubuntu3 | http://us.archive.ubuntu.com/ubuntu focal/main amd64 Packages
Show Available Package Version with Apt List
Nearly equivalent to madison:
apt list -a <package name>
ref: [12]
Issues
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: [13]
Install these packages without verification?
try...
Solution:
apt-get clean ; apt-get update
# or
apt-get install debian-keyring debian-archive-keyring
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: 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:
# gpg --keyserver wwwkeys.eu.pgp.net --recv-keys [MISSING_KEY_ID] # apt-key add /root/.gnupg/pubring.gpg # apt-get update
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
keywords
- ↑ https://askubuntu.com/questions/916598/how-to-install-a-package-greater-than-or-equal-to-a-particular-version
- ↑ https://askubuntu.com/questions/916598/how-to-install-a-package-greater-than-or-equal-to-a-particular-version
- ↑ https://unix.stackexchange.com/questions/578460/specify-apt-get-a-minimum-version-to-be-installed
- ↑ https://askubuntu.com/questions/916598/how-to-install-a-package-greater-than-or-equal-to-a-particular-version
- ↑ https://askubuntu.com/questions/916598/how-to-install-a-package-greater-than-or-equal-to-a-particular-version