How to Install, Manage, and Remove .deb Packages on Ubuntu: A Complete Beginner-to-Intermediate Guide

1. Introduction

Ubuntu is a popular Linux distribution used by many users. While installing software using deb packages is common, it may feel a bit challenging for beginners. This article explains how to install and remove deb packages, along with important precautions. Visual guides and terminology explanations are included to support users from beginner to intermediate levels.

2. What Is a deb Package?

A deb package is a package format used in Debian-based Linux distributions, such as Ubuntu. Files with the .deb extension include software, related files, and installation scripts. Other package formats include RPM (for Red Hat-based systems), Snap, and Flatpak. deb packages automatically resolve system dependencies, making installation smooth and efficient.

What Are Dependencies?

Dependencies are other software or libraries required for a particular program to run. deb packages reduce user effort by resolving these dependencies automatically. For example, when installing the vlc media player, the necessary libraries for VLC to run are installed automatically.

3. Preparing to Install deb Packages

Before installing deb packages, ensure the following tools are available:

  • apt: A command-line tool used to install packages from the official Ubuntu repositories. It is installed by default.
  • dpkg: A low-level package management tool for handling deb files directly. It is also installed by default.

To ensure your system is up to date, run the following command:

sudo apt update && sudo apt upgrade

4. How to Install deb Packages

4.1 Installing from the Official Repository

Installing software from the official repository offers the highest compatibility and is the safest method. For example, to install the vlc media player, run the following command:

sudo apt install vlc

After running the command, follow the prompts. Dependencies will be resolved automatically, and all required packages will be installed.

4.2 Installing from a Local deb File

If the package is not available in the official repository, you can install a deb file provided by the developer. After downloading the deb file, verify its integrity. Use the sha256sum command to confirm that the checksum matches the one provided on the official website.

sha256sum /path/to/package.deb

Expected Output: Running this command displays the SHA256 checksum of the file. Make sure it matches the value shown on the official site. If it does not match, the file may be corrupted or tampered with, and installation should be aborted.

Once integrity is confirmed, install the package using the following command (replace /path/to/package.deb with the actual file path):

sudo apt install ./path/to/package.deb

This method is easier and safer than using dpkg because apt automatically handles dependency resolution.

Using dpkg
You can install a deb file with the following commands, but note that dependencies may not be resolved automatically.

sudo dpkg -i /path/to/package.deb
sudo apt-get install -f

Important: After running dpkg, execute sudo apt-get install -f to resolve missing dependencies.

4.3 Installing deb Packages Not in the Repository

You can use a PPA (Personal Package Archive) to install packages that are not available in the official repositories. However, since PPAs are maintained by third parties, they must be used with caution.

Example of adding a PPA:

sudo add-apt-repository ppa:example/ppa
sudo apt update
sudo apt install package_name

To revert packages installed from a PPA back to the official repository version, use ppa-purge:

sudo apt install ppa-purge
sudo ppa-purge ppa:example/ppa

Security and GPG Key Verification for PPAs

Always verify the trustworthiness of a PPA before adding it. Choose PPAs maintained by reputable developers or communities. Check feedback, reviews, and GPG keys provided on the official site. Add the GPG key as follows:

wget -qO - https://example.com/repo.gpg.key | sudo apt-key add -

Managing PPAs

To list all PPAs on your system, run:

ls /etc/apt/sources.list.d/

To remove a specific PPA:

sudo add-apt-repository --remove ppa:example/ppa

5. Removing and Cleaning Up deb Packages

5.1 Removing Packages

Use the apt command to remove a package. For example, to remove vlc:

sudo apt remove vlc

To remove it completely, including configuration files:

sudo apt purge vlc

If you installed a package using dpkg, remove it with:

sudo dpkg -r package_name

5.2 System Cleanup

Remove unnecessary packages and clean cache files to keep your system tidy.

sudo apt autoremove
sudo apt clean

5.3 Troubleshooting

If the standard removal procedure fails, you can forcefully remove a package with the following command. Use caution:

sudo dpkg --remove --force-remove-reinstreq package_name

If you encounter an error such as “package architecture (i386) does not match system (amd64),” enable multi-architecture support:

sudo dpkg --add-architecture i386
sudo apt update

6. Important Notes When Installing deb Packages

  • Dependency Issues: When installing using dpkg, missing dependencies may occur. In such cases, run sudo apt-get install -f to resolve them.
  • Security: It is extremely important to install deb files only from trusted sources. Files downloaded from unofficial sites may contain malware or malicious code. Always download packages from official sources or reputable repositories. Verifying digital signatures and GPG keys ensures authenticity and enhances system security.

Use the following command to verify a package’s GPG signature:

gpg --verify /path/to/package.deb

Note: Even if a file does not have a digital signature, it is generally safe if downloaded from an official source. However, avoid installing files from untrusted locations.

  • Regular Backups: Before installing PPAs or unknown .deb files, create a full system backup. This allows you to restore your system if any issues occur.

7. Practical Example: Installing Google Chrome

A common example of software distributed as a deb package is Google Chrome. Download the file from the official website and install it with the following command:

sudo apt install ./google-chrome-stable_current_amd64.deb

This command automatically resolves dependencies and installs Google Chrome. Follow any prompts displayed during installation.

8. Installing Using the Graphical User Interface (GUI)

Using the GUI is convenient for users unfamiliar with the command line. Tools like the Ubuntu Software Center and GDebi allow easy installation of deb files.

Installing via Ubuntu Software Center

  1. Double-click the downloaded deb file. The Ubuntu Software Center will open automatically.
  2. Review the package details, then click the Install button.
  3. Enter your administrator password if prompted. Installation will complete within a few seconds or minutes.

Installing with gdebi

gdebi is a lightweight tool that automatically resolves dependencies when installing deb packages.

  1. Install gdebi:
    bash sudo apt install gdebi
  2. Right-click the downloaded deb file and select Open with GDebi Package Installer.
  3. Click Install and enter your administrator password if required.

9. Community Support and Additional Resources

Ubuntu has an active community that provides troubleshooting assistance and technical resources:

  • Ubuntu Forums: Ubuntu Forums – A forum for discussing Ubuntu-related questions and topics.
  • Ask Ubuntu: Ask Ubuntu – A community-driven Q&A site for technical questions.
  • Official Ubuntu Documentation: Ubuntu Documentation – The official documentation for Ubuntu.

These resources allow users to search for known issues, review solutions, or post their own questions for community support.

10. Summary of Commonly Used Commands

  • System Update:
    bash sudo apt update && sudo apt upgrade
  • Install from Official Repository:
    bash sudo apt install package_name
  • Install from deb File:
    bash sudo apt install ./path/to/package.deb
  • Add a PPA:
    bash sudo add-apt-repository ppa:example/ppa
  • Remove a PPA and Revert to Official Repository:
    bash sudo ppa-purge ppa:example/ppa
  • Remove a Package:
    bash sudo apt remove package_name
  • Completely Remove a Package (including config files):
    bash sudo apt purge package_name
  • Automatically Remove Unused Packages:
    bash sudo apt autoremove
  • Clean Package Cache:
    bash sudo apt clean
  • Verify Digital Signature:
    bash gpg --verify /path/to/package.deb

11. Conclusion

deb packages are an extremely useful tool for managing software on Ubuntu. Installing from the official repository is the safest and easiest method, but you can also install packages using deb files from other trusted sources. By paying close attention to security and verifying your sources, you can maintain system stability and safety. Mastering both command-line and GUI installation methods will lead to a more efficient software management experience.

12. Additional Tips and Best Practices

  • apt-cache command: Use apt-cache search package_name to search for package information.
  • apt-mark command: Hold a package to prevent automatic upgrades.
    bash sudo apt-mark hold package_name sudo apt-mark unhold package_name
  • Regular Updates: Keep system packages updated to maintain security.
  • Advanced Package Management Tools: Tools like dpkg-query and aptitude help retrieve detailed package information and perform advanced package operations.

13. Troubleshooting and Common Errors

  • “Dependency is not satisfiable” Error: Occurs when required dependencies are missing. Resolve it with sudo apt-get install -f or enable the “universe” or “multiverse” repositories.
  • “Unable to locate package” Error: The package name may be incorrect, or the repository may not be added. Update the package list using sudo apt update.
  • “Broken packages” Error: Occurs when a package becomes corrupted during installation. Fix it using:
    bash sudo dpkg --configure -a sudo apt --fix-broken install
  • Network Issues: If you see a “Failed to fetch” error, check your internet connection or modify the source list to use a different mirror server.

14. Quick Reference Cheat Sheet

  • System Update and Upgrade:
    bash sudo apt update && sudo apt upgrade
  • Install from Repository:
    bash sudo apt install package_name
  • Install from deb File:
    bash sudo apt install ./path/to/package.deb
  • Remove a Package:
    bash sudo apt remove package_name
  • Clean Cache:
    bash sudo apt clean

Final Summary

Mastering the installation and management of deb packages is an essential skill for effectively using Ubuntu. This article provided a comprehensive overview—from basic installation methods to troubleshooting and security practices—so that users from beginner to intermediate levels can confidently manage software. If any issues arise, rely on community support and official documentation to maintain a secure and efficient system.

侍エンジニア塾