Last active
June 5, 2025 03:09
-
-
Save henri/eb26bf5c1b78d73e0bf7fb89424c325a to your computer and use it in GitHub Desktop.
apt cheat sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### APT Tips (tested only on Ubuntu) | |
## | |
## Problem : | |
## The following packages have been kept back | |
## | |
## Possible Solutions (depending on the situation) : | |
# non-manual upgrade of kept back packages (safest) : | |
sudo apt-get --with-new-pkgs upgrade | |
sudo apt-get --with-new-pkgs upgrade <list of packages kept back> | |
# upgrade / install of new package version (not as great but is sometimes needed) : | |
sudo apt-get install <packages which you will force upgarde / install> | |
# list installed version of particular package | |
sudo apt-cache policy <package-name> | |
sudo apt list -a <package-name> | |
# search for available versions of a particular pacakge | |
# install rmadison from devscripts package eg : | |
# sudo apt-get install devscripts | |
sudo rmadison <package-name> | |
# upgrade to specific version of PHP (for example) - use policy example above to find the available versions | |
sudo apt-get install php5=5.5.16+dfsg-1+deb.sury.org~precise+2 | |
# use aptitude to upgrade | |
sudo aptitude (then click "+" "+" "g" "g" then proceed by saying yes and finally quit aptitude). | |
# dist-upgrade approach - danger will robbinson this can break stuff : | |
sudo apt-get dist-upgrade | |
# maybe just upate single package | |
sudo apt-get install --only-upgrade <package-name> | |
# enable auto updates on ubuntu (you will want to edit the file to configure things how you like) | |
sudo apt install unattended-upgrades && vim /etc/apt/apt.conf.d/50unattended-upgrades | |
# if you have errors like | |
# dpkg: error processing package update-notifier-common (--configure): | |
# installed update-notifier-common package post-installation script subprocess returned error exit status 1 | |
# Errors were encountered while processing: | |
# update-notifier-common | |
# E: Sub-process /usr/bin/dpkg returned an error code (1) | |
cd /var/lib/dpkg | |
sudo mv -i info info.bak | |
sudo mkdir info | |
sudo apt-get upgrade | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# dump the apt installed packages | |
# or save yourself pain and use a tool like timeshift | |
# or do both + remember other package systems cargo, faltpack, etc... | |
# | |
# (C) Henri Shustak 2020 | |
# Released under GNU GPL 3 or later (now youare infected by freedom) | |
# | |
# version 1.0 | |
# | |
# todo - support other operating systems (yum, pacman etc) | |
user_name=$(whoami) | |
host_name=$(hostname) | |
day=$(date +%w) | |
apt_dump_dir="${HOME}/backup-config/apt" | |
if ! [ -d ${apt_dump_dir} ] ; then mkdir -p ${apt_dump_dir} ; fi | |
apt_dump_file_all="${apt_dump_dir}/${host_name}-${user_name}-apt-list-all-$day" | |
apt_dump_file_manual="${apt_dump_dir}/${host_name}-${user_name}-apt-list-manual-$day" | |
apt_dump_file_manual_with_details="${apt_dump_dir}/${host_name}-${user_name}-apt-list-manual-with-details-$day" | |
if [ -d "${apt_dump_dir}" ] ; then | |
dpkg --get-selections > "${apt_dump_file_all}" | |
apt-mark showmanual > "${apt_dump_file_manual}" | |
apt list --manual-installed > "${apt_dump_file_manual_with_details}" | |
else | |
echo "apt_dump_dir not avaialble : ${apt_dump_dir}" | |
exit -99 | |
fi | |
# Restore with the following commands (you will need to massage to work with the details data file) | |
# sudo dpkg --set-selections < backup_file_path/backup_file | |
# sudo apt-get update && sudo apt-get -u dselect-upgrade |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment