do not install needless bullshit

apt install --no-install-recommends <PACKAGE>

Although, recommended packages are most of the time useful.

Install a more recent version of a package

Say you are in stable, and want a package from testing.

Add the following line to /etc/apt/sources.list

deb-src http://mirrors.gandi.net/debian/ testing main contrib non-free

Then create a temp directory

cd /tmp
mkdir blabla
cd blabla

and do the following:

apt-get build-dep your-package
apt-get source -b your-package

After that last commands finishes, install the .deb it created, using dpkg -i.

Notes

The build-dep step might fail, complaining about a dependency not available. Install it from testing using this very same method.

Choose alternatives for a particular service

update-alternatives --list java
update-alternatives --config java

downgrade a package

Say a version of a package got broken by apt-get upgrade. If you have luck, both the culprit (current version)and the previous .deb for that package will be at /var/cache/apt/archives/. Use dpkg -i to install it.

Another option is to download a package from the debian package archive.

freeze a package version

aptitude hold paquete

libc

So you've messed up things, and installed testing's libc in your rustyshiny stable server. How to fix it?

Open aptitude, and choose manually the version of the packages that got upgraded, from the testing version to the stable one. Do it by placing the cursor over the proper version, and hitting +.

Do the same with libc.

Apply changes.

If apt-get complains because there is no ldconfig, download the libc package manually, extract it and copy the required binaries to the proper places

dpkg-deb -x libc6*.deb libc6-unpacked/
sudo cp libc6-unpacked/sbin/ldconfig* /sbin/

you should be good to go after doing that.

As the bot said:

jordanm wants you to know: This may or may not work for you, but if you've got nothing to lose then try it. (a) Change sources.list (b) aptitude update (c) aptitude and then search for the upgraded packages, hit enter on them, select the correct version (d) do the same for libc6 (e) search for broken packages by hitting "/" and searching for "~b" and then fix them in the same way (f) once you have no more broken packages, hit 'g' See