15 most useful dpkg tips for beginners
Debian software packages (i.e. deb files) are managed with
dpkg, according to DistroWatch top three most popular GNU/Linux distributions are Debian based, including Ubuntu and Linux Mint. We are going to talk about few most useful dpkg commands for beginners, this tutorial is somewhat long , so bookmark this page for future reference.
1. how to install a deb file
sudo dpkg -i deb_file_name.deb
here deb_file_name is your software package name.
2. how to install multiple deb file
assume you have many deb files in a folder, you don’t know which one to install first, many of them depends on other deb files, then open up a terminal, go to that directory with cd and simply run
sudo dpkg -i *.deb
All deb files will be properly selected and installed automatically.
3. fix missing dependency problem after installing a deb file
Your deb file may be dependent on one or many other deb files, in such case you will get an error while dpkg processing the package. To fix such errors, simply run
sudo apt-get install -f
after installing the package.
4. check if a package is installed or not
want to check about a package is installed or not ? simply run
dpkg -l | grep your_package_name
here your_package_name may not be same as your deb file name, but it should be matching to your original deb package file name.
5. remove a package
To remove an installed package, run
sudo dpkg -r your_package_name
here your_package_name is not the name of your deb file, it must be the name as it is installed. A simpe hack, after
sudo dpkg -r type first few words of your package name then press the Tab key two times, matching names will appear on the terminal, like
sudo dpkg -r gnome[Tab][Tab] , this feature is known as Tab auto complete .
WARNING! typing a different package name, even a little bit, may remove an important package. So be careful while removing any package.
6. purge a package
Sometime simple removing does not works as wished, or it is impossible to remove a package due to some misconfiguration. Then you you may try to purge a package, purging removes everything including changes made by user.
sudo dpkg -P your_package_name
Be extra careful while purging a package.
7. take backup of an installed package
Take a backup of your already installed package with dpkg-repack, very useful if you are testing newer version of a package and there is a chance of breaking something. If dpkg-repack is not installed, install it
sudo apt-get install dpkg-repack
sudo dpkg-repack your_package_name
this will create a deb file on your current directory.
8. know details of an installed package
know more about an already installed package.
dpkg -s package_name
9. unpack a deb file
Deb files are basically an ar archive containing 3 files, two compressed tar archives and a text file. This is very useful if you want to make a little change on that deb file. There are many way to extract a deb file, like with gnome’s archive manager file-roller or with dpkg-deb, etc. An example, extracting the
apache2_2.4.10-11_amd64.deb file with with dpkg-deb .
mkdir apache2 #create the directory to extract dpkg-deb --raw-extract apache2_2.4.10-11_amd64.deb apache2/
10. repack an unpacked deb file
Now repack the deb file after extracting, simply with dpkg , assuming you have the extracted the package to a folder named apache2 .
dpkg -b apache2/
this will create a deb file with apache2.deb name.
11. configurations messed up ? revert back to default
Think you have rendered your system unusable by some software misconfiguration, this is a very common problem while installing nVIDIA or AMD non-free graphics drivers. Revert back to default configuration of any package with
dpkg-reconfigure , like bellow
sudo dpkg-reconfigure xserver-xorg
12. add a 32-bit package support on a 64-bit system
indroduction to debian multiarch
Do you want to run a 32-bit software on a 64-bit Ubuntu or Debian installation ? If yes, multiarch is for you. Know your default architecture with
This will return your default dpkg architecture either amd64 or i386, amd64 is 64-bit and i386 is for 32-bit system
add a 32-bit package support on a 64-bit Ubuntu system
su -c "echo 'foreign-architecture i386' > /etc/dpkg/dpkg.cfg.d/multiarch" sudo apt-get update
sudo apt-get update , you could install a 32-bit package. example
sudo apt-get install libc6:i386
13. add different architecture package support on Debian
To add 32-bit support on 64-bit machine run
sudo dpkg --add-architecture i386 sudo apt-get update
To add 64-bit support on 32-bit machine run
sudo dpkg --add-architecture amd64 sudo apt-get update
know which different architecture is present
14. remove a foreign architecture support
To remove a foreign architecture on Ubuntu , simply delete the i386 line of the
/etc/dpkg/dpkg.cfg.d/multiarch file or remove the file and run
sudo apt-get update .
To remove any foreign architecture on Debian, run
sudo dpkg --remove-architecture (architecture_name)
sudo dpkg --remove-architecture i386 # to remove i386 architecture sudo dpkg --remove-architecture amd64 # to remove amd64 architecture sudo apt-get update
15. how to make a debian package from source
To avoid recompilation and keep track on your packages easily, after compiling the software source make a deb package.
Probably you know how to compile a source package, if not here is a little intro, we are going to compile the gnu nano editor from source, assuming the nano-2.2.6.tar.gz archive downloaded on home directory and it requires at least the build-essential package.
sudo apt-get install build-essential tar -xf nano-2.2.6.tar.gz cd nano-2.2.6/ ./configure make
. . . and you are done . Now build the deb package, there are many way to do this, but here we are going to talk about only checkinstall and dh-make .
sudo apt-get install checkinstall sudo checkinstall -D make install
sudo apt-get install autotools-dev fakeroot dh-make build-essential dh-make --createorig dpkg-buildpackage -rfakeroot
the debian package is ready and you can install it with
dpkg -i package_name.deb
You can read more about dpkg and debian package building at Debian Wiki .
Do you have any question ? just drop a comment, we’d be happy to assist you. Feel free to share this tutorial with your friends.