In this first post, we will speed up dpkg, in a later post, we shall speed up apt.
I don’t know about you, but for a long time I have been frustrated with both dpkg and apt’s speed (or should that be lack thereof), however recently I stumbled along some information that should increase the speed of installing, removing, updating etc.
NOTE: Although on my system this all went well, I can accept no responsibility for this going wrong, it may be wise to experiment in a virtual machine first.
The main bottleneck in dpkg’s speed, is reading from its database. This database is inefficient as it is made up of hundreds of individual files, rather than a proper database. To solve this, we are going to use a program called tdpkg; it does this by storing the dpkg database in either an sqlite or a tokyocabinet database.
- Open up a Terminal (Applications>Accessories>Terminal) and get ready!
- (Optional) Backup your dpkg database incase anything goes wrong (this could take a while)
cp -r /var/lib/dpkg/info ~/dpkg-backup
- Download the libraries necessary to compile tdpkg
sudo apt-get install build-essential libsqlite3-dev libtokyocabinet-dev
- Download the latest source of tdpkg and navigate into the source
git clone http://git.gitorious.org/lethal-works/tdpkg.git && cd tdpkg
- Now you must compile tdpkg, using the database library you want. TokyoCabinet is faster than sqlite, however sqlite can handle multiple requests better. If you are like me and shallow, and want pure speed, pick TokyoCabinet🙂
- tdpkg should now compile into a shared library file called libtdpkg.so. We are now going to move this file into /usr/lib and edit the system-wide bash file, so that when dpkg is called, this library is loaded at the same time.
- To do this, run the command
cp libtdpkg.so /usr/lib/libtdpkg.so
echo alias dpkg="LD_PRELOAD=/usr/lib/libtdpkg.so /usr/bin/dpkg" >> /etc/bash.bashrc
- You should now be done! Reboot your computer and dpkg should be a lot quicker!
To undo changes:
- Run the command
sudo rm /usr/lib/tdpkg.so tdpkg
- Run the command
gksudo gedit /etc/bash.bashrc
and delete the line at the bottom that says:alias dpkg="LD_PRELOAD=/usr/lib/libtdpkg.so /usr/bin/dpkg"