logo of Akmatori
02.01.2025

Fixing the "dpkg: error parsing file" Issue During Package Installation

head-image

Package management errors can disrupt your workflow, especially when working with critical tools. One common issue is the error related to invalid version formatting during the installation or upgrade process in apt-get.

In this guide, we’ll break down the error and offer practical solutions.


The Error: What Does It Mean?

When running the following command:

sudo apt-get install my-app

You may encounter the following output:

dpkg: error processing archive /var/cache/apt/archives/my-app_abc-test-version_amd64.deb (--unpack):
 parsing file '/var/lib/dpkg/tmp.ci/control' near line 2 package 'my-app':
 'Version' field value 'abc-test-version': version number does not start with digit
Errors were encountered while processing:
 /var/cache/apt/archives/my-app_abc-test-version_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Why This Happens

This issue occurs because the Debian package (.deb) contains an invalid Version field in its control file. The version string abc-test-version does not start with a digit, violating Debian's package naming conventions. A valid version string must follow this format:

[epoch:]upstream_version[-debian_revision]

Here, the upstream_version must start with a number, which is not the case in this error.


Step-by-Step Solution

1. Remove the Corrupted Package

First, remove the package causing the issue:

sudo dpkg --remove --force-remove-reinstreq my-app

This command forces dpkg to remove the problematic package, even if it is partially installed.


2. Clean the Local Package Cache

Clear the cached .deb file to avoid reusing the problematic package during future installations:

sudo apt-get clean
sudo rm -f /var/cache/apt/archives/my-app_abc-test-version_amd64.deb

3. Download a Fixed Package

Check with the package provider or repository for a corrected version of the .deb file. Ensure the version string starts with a digit. If you have the fixed .deb file, install it manually:

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

If the fixed package is in the repository, use apt-get:

sudo apt-get update
sudo apt-get install my-app

4. Manually Edit the Version String (Advanced Fix)

If a corrected version is not available and you must install the package, you can edit the control file within the .deb package to fix the version string.

  • Extract the .deb File

dpkg-deb -R /var/cache/apt/archives/my-app_abc-test-version_amd64.deb /tmp/my-app
  • Modify the Control File

Open the control file:

nano /tmp/my-app/DEBIAN/control

Locate the Version field and change it to a valid value (e.g., 1.0.0-test):

Version: 1.0.0-test
  • Rebuild the Package

Repack the .deb file:

dpkg-deb -b /tmp/my-app fixed-my-app.deb

Install the fixed package:

sudo dpkg -i fixed-my-app.deb
sudo apt-get install -f

5. Prevent Future Issues

To avoid similar errors, ensure packages meet Debian's packaging standards before installation. Work with trusted repositories and validated packages.


Simplify Package Management with Akmatori

Tired of manual troubleshooting? Automate your infrastructure with Akmatori. Akmatori streamlines incident management, reducing downtime and making troubleshooting effortless. It’s your trusted partner in DevOps and SRE workflows.


Affordable Cloud Hosting Solutions

Need reliable cloud servers? Check out Gcore for high-performance virtual machines and bare metal servers at unbeatable prices. Gcore provides global coverage to suit your needs.


Conclusion

The "version number does not start with digit" error in dpkg can disrupt your operations, but it's fixable with the steps above. Whether you manually edit the package or rely on official updates, understanding this issue will help you maintain a smooth package management experience.

If you found this guide helpful, explore more tips on DevOps and Linux engineering on our blog!

Maximize your website or application's performance and reliability!