Showing posts with label apt. Show all posts
Showing posts with label apt. Show all posts

Saturday, August 27, 2022

Debian: Clean up dpkg rc packages

rc means that the package is not completely removed.
dpkg --list | grep "^rc" | cut -d " " -f 3 | \
	xargs sudo dpkg --purge

Thursday, November 14, 2013

How to build Python deb package from source

You need a newer python version that is not available with the Debian package management system. You can compile it from source and install but that usually takes a lot of time. It would be better to build a deb instead and install it on as many machines as you need. You can use checkinstall for this.
apt-get install checkinstall
The instruction how to compile python from source is here. Once you compiled python here is a simple command that does the rest for you:
checkinstall -y --pkgname=python2.7
Once it finishes you will get a deb file in the current directory. You can install it this way:
dpkg -i python2.7_2.7.6-1_i386.deb
Here is how to remove it:
apt-get remove --purge python2.7
Note, packages built with checkinstall are not updated by OS package management system, thus updates need to be provided manually.

Thursday, October 4, 2012

apt-get: update only required translations

apt Acquire::Languages can be set to declare which translations you want downloading. The variable "environment" specifies that apt should check $LC_MESSAGES. Here we go:
# eliminate any lists you might have
rm -rf /var/lib/apt/lists/
# set languages you need
echo 'Acquire::Languages { "environment"; "en"; };' > \
  /etc/apt/apt.conf.d/99lang
# update lists
apt-get update
If you need just English, it is okay just remove apt lists.

Wednesday, February 15, 2012

How to Revert Broken Package in Debian

You just made upgrade of your Debian testing box and noticed something went wrong, some daemon not starting and you have no idea what to do until the bug will be fixed. Fortunately, you are able to revert broken package in Debian. Here we are going revert broken bind9 package version 1:9.8.1.dfsg.P1-2 and replace it with last known to work.
  1. We need to find last known to work version of the broken package. Take a look at /var/log/apt/history.log. You should be able to find information about the package failed to install/configure:
    Upgrade: ..., bind9:i386 (9.7.3.dfsg-1+b1, 
    9.8.1.dfsg.P1-2)...
    
    So here version 9.7.3.dfsg-1+b1 is replaced by 9.8.1.dfsg.P1-2. Thus we found last working version.
  2. Since we know version (9.7.3.dfsg-1+b1) of the bind9 package we can install it from snapshot.debian.org. Go to that site and search for your package. You will get a list of various versions available. Follow link for with version that you found previously. You will get a list of various options, including source, architecture specific files, etc.
    bind9_9.7.3.dfsg-1+b1_i386.deb
    Seen in debian on 2011-04-20 22:16:02 in 
    /pool/main/b/bind9.
    
    Follow link /pool/main/b/bind9. In my case it was:
    http://snapshot.debian.org/archive/debian/20110420T221602Z/pool/main/b/bind9/
    
  3. Add snapshot url to file /etc/apt/sources.list:
    deb http://snapshot.debian.org/archive/debian/20110420T221602Z testing main
    
  4. Update your apt repository with the following command:
    apt-get -o Acquire::Check-Valid-Until=false update
    
  5. Have a look at updated package information:
    apt-cache showpkg bind9
    
    You should be able to see something like this:
    Versions: 
    1:9.8.1.dfsg.P1-2 ...
    1:9.7.3.dfsg-1 ...
    
    1:9.7.3.dfsg-1 is the version we need.
  6. Remove broken package and related dependencies:
    apt-get remove bind9
    apt-get autoremove
    
  7. Install version we need:
    apt-get install bind9=1:9.7.3.dfsg-1
    
    Since it complains:
    The following packages have unmet dependencies:
     bind9 : Depends: bind9utils (= 1:9.7.3.dfsg-1) but 1:9.8.1.dfsg.P1-2 is to be installed
    
    ... let add that one dependency for bind9utils as well.
    apt-get install bind9=1:9.7.3.dfsg-1 bind9utils=1:9.7.3.dfsg-1
    
At this point you have reverted broken bind9 package to last known to be working.

Package pinning

We will use apt pinning feature to prevent packages from being upgraded. Just create a file /etc/apt/preferences.d/bind9 and add the following:
Package: bind9                                                                 
Pin: version 1:9.7.3*                                                          
Pin-Priority: 1001                                                             
                                                                               
Package: bind9utils                                                            
Pin: version 1:9.7.3*                                                          
Pin-Priority: 1001
The next time you run upgrade these two packages remain untouched.

Monday, February 7, 2011

Email Available Updates for Debian

Before you proceed below please check:
  • Simple apt daily update script, see here.
  • Configure exim4 to send messages by smarthost, no local mail, see here.
We are going enhance daily update script by ability to send a list of new updates to mail.
#!/bin/sh

mailto=debian-updates@dev.local

# Download only; package files are only retrieved, not 
# unpacked or installed.
apt-get -dqq update
apt-get -dyqq upgrade

has_upgrades=$(apt-get -s upgrade | grep ^Inst)
if [ "$has_upgrades" ] ; then
    echo "$has_upgrades" | mail -s \
    "Updates for $(hostname) on $(date +%Y-%m-%d)" \
    $mailto
fi
Alternatively consider using apticron, read more here.

Friday, April 30, 2010

Simple apt daily update script

Here is a simple apt update script (file /usr/local/sbin/apt-update):
#!/bin/sh

# Download only; package files are only retrieved, not unpacked or
# installed.
apt-get -dqq update
apt-get -dyqq upgrade
Make this file executable:
chmod +x /usr/local/sbin/apt-update
Run it by cron per schedule (file /usr/local/etc/cron.d/apt-update):
#
# Regular cron jobs for apt-update
#
SHELL=/bin/sh
PATH=/usr/local/sbin:/bin:/usr/bin
LOG=/dev/null

# Run on Sun, Tue, Thu at 2:05 AM
# m h dom mon dow user  command
05 2 * * 0,2,4 root test -x /usr/local/sbin/apt-update && apt-update > $LOG
Let cron know about our scheduled apt-update:
ln -s /usr/local/etc/cron.d/apt-update /etc/cron.d/cron-apt-update

Friday, April 23, 2010

The Debian package management system

Installing packages

apt-get install package1 package2

Updating database

apt-get update

Reinstalling packages

apt-get install --reinstall package1

Pinning packages

If you need to pin a specific version of the package from being upgraded you can put the following into the /etc/apt/preferences.d/ directory (file libsasl2):
Package: libsasl2-2
Pin: version 2.1.23.dfsg1-8
Pin-Priority: 1001

Searching database

The arguments to apt-cache search are regular expressions themselves, and if more than one argument is specified, all of them have to match for a package to be included in the output.
apt-cache search packge1
apt-cache show packge1

Inquiring about package dependencies

Depends:
apt-cache depends packge1
Reverse Depends:
apt-cache rdepends packge1

Deinstalling and purging packages

To remove a package’s configuration files as well, specify the --purge option.
apt-get remove package1
apt-get remove --purge package1

Upgrading a stable system

Executing this update/upgrade sequence on a regular basis will keep the system running smoothly and securely.
apt-get update
apt-get --show-ugraded upgrade

Upgrading to a new Debian release

When it is time to upgrade the entire system.
apt-get --show-upgraded dist-upgrade
With apt-get dist-upgrade, APT can pull in new packages and even remove packages that have been obsoleted.

Housekeeping

APT keeps its packages in a local cache (unless the file or cdrom acquisition method is used). Over time, the cache directory can fill up and consume vast amounts of space, especially on systems tracking testing or unstable. APT does not manage the contents of its cache directory /var/cache/apt/archives automatically. Instead, apt-get provides two methods to erase files in the cache. The first cleanup method checks each file in the cache and erases it only if it is not available on the mirrors anymore.
apt-get autoclean
The following removes all DEB files regardless of their availability on the mirror or not.
apt-get clean

Resolving problems

Let APT handle the inconsistency automatically:
apt-get --fix-broken install

cron-apt

The cron-apt tool is designed to be invoked by cron to perform routine APT operations. It uses several directories below /etc/cron-apt for its configuration.
# Every night at 4 o'clock.
0 4 * * * root test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt
Out of the box, the tool comes to life at a random moment between 4 and 5 o’clock (you can adjust schedule in /etc/cron.d/cron-apt) to update its cache and download all upgraded packages without installing them (using the --download-only option to apt-get).
apt-get install cron-apt
I highly discourage the use of cron-apt to upgrade packages from the main Debian archive.