According to DistroWatch top three most popular GNU/Linux distributions are Debian based, including Ubuntu and Linux Mint.
Debian software packages (i.e. deb files) are managed with dpkg
, so we are going to talk about few most useful dpkg commands for beginners.
This tutorial is somewhat long , so you may want to bookmark this page for future reference.
Contents
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 bad configuration. 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
then run
sudo dpkg-repack your_package_name
This will create a deb file on your current directory.
8. Know details of an installed package
To know more about an already installed package, use the command below.
dpkg -s package_name
9. Unpack a deb file
Deb packages 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 bad software configuration, 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 dpkg --print-architecture.
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
After running 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
dpkg --print-foreign-architectures
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
.
with checkinstall
sudo apt-get install checkinstall sudo checkinstall -D make install
with dh-make
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 .
Conclusion
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.
indra says
Vai chalia ja........