This error occurs when a package has a malformed version string containing spaces instead of a valid Debian version format. This typically happens when shell scripts use single quotes instead of backticks for command substitution, or when manually editing package files. The version field must follow Debian's strict format without any whitespace, or dpkg will reject the package.
The dpkg package manager strictly validates version strings according to Debian's versioning scheme, which follows the format [epoch:]upstream_version[-debian_revision]. Version strings must not contain any spaces and must begin with a digit or epoch number. When dpkg encounters a version like "uname -r" (with a space from unexecuted backticks) or any version containing spaces, it fails validation because spaces are not legal characters in Debian version identifiers. This validation is critical because version strings are used for dependency resolution and package upgrades, so malformed versions would break package management operations.
First, determine which package is causing the error. Run the command that triggers the error and note the exact error message:
sudo apt updateOr if installing a specific package:
sudo apt install package-nameThe error message will show the exact version string with spaces. For example:
dpkg: error: version 'uname -r' has bad syntax: version string has embedded spacesThis tells you the version field contains the literal string "uname -r" (with a space) instead of the kernel version.
If you are installing a local .deb file you created or downloaded, extract and inspect its control file:
cd /tmp
ar x /path/to/package.deb
tar -xzf control.tar.gz
cat controlLook for the Version field:
Package: mypackage
Version: 1.0.0
Architecture: amd64The Version field must not contain any spaces and must start with a digit or epoch number. Valid version examples:
- 1.0.0
- 1:9.10.3.dfsg.P4-12.3+deb9u4
- 2020.12.16~dfsg-1~ubuntu~20.04.1
If the version contains spaces, you must fix the source and rebuild the .deb file correctly.
If the error comes from a system package (from apt repositories), check the dpkg database:
sudo cat /var/lib/dpkg/status | grep -A 20 "Package: problematic-package-name"Look at the Version line. It should be clean without spaces:
Version: 1.2.3-4~ubuntu1If it shows something like "Version: uname -r" or has embedded spaces, the package metadata is corrupted.
You can also query installed packages:
dpkg -l | grep problematic-packageIf you are building your own .deb package, check your debian/control or debian/rules file. Look for any backtick issues:
Wrong (using single quotes):
echo "Version: 'uname -r'" > controlCorrect (using backticks):
echo "Version: $(uname -r)" > controlOr better, hardcode the version:
echo "Version: 5.15.0-56-generic" > controlRebuild the .deb file:
cd /path/to/package
dpkg-deb --build . ../package.debThen test installation:
sudo dpkg -i ../package.debUse dpkg's built-in validation to check if a version string is valid (requires dpkg 1.18.16+):
dpkg --validate-version "1.0.0"
echo $?Return codes:
- 0 = valid version
- 1 = invalid but might work in lax contexts
- 2 = invalid and will definitely fail
Test your version:
dpkg --validate-version "uname -r"
# Returns 2 (invalid)
dpkg --validate-version "5.15.0-56"
# Returns 0 (valid)Use this to verify any custom version strings before creating packages.
If the error comes from a system package and is due to corruption in /var/lib/dpkg/status:
# Create a backup first
sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.backup
# Reconfigure packages
sudo dpkg --configure -aIf a specific package is broken:
# Remove the broken package
sudo dpkg --remove --force-remove-reinstreq broken-package-name
# Reinstall it
sudo apt install --reinstall broken-package-nameIf corruption is severe:
# Clear the available database and rebuild
sudo dpkg --clear-avail
sudo apt update
# Reconfigure all packages
sudo dpkg --configure -aAfter fixing the version string or package metadata, test that dpkg accepts it:
sudo apt updateIf installing a specific package:
sudo dpkg -i /path/to/fixed-package.debOr using apt:
sudo apt install package-nameCheck package status:
dpkg -l | grep package-name
sudo dpkg -s package-nameIf the error still occurs, double-check the version field one more time:
dpkg -I /path/to/package.deb | grep VersionThe version must be a single string with no spaces.
Debian version strings follow a strict format specified in deb-version(5) to enable proper sorting and comparison. The format [epoch:]upstream_version[-debian_revision] ensures that package management systems can reliably determine which version is newer. Spaces are not allowed anywhere in this string because dpkg uses whitespace as a field delimiter in the control file format. When building packages with fpm (Effing Package Manager), this error can occur if version strings are not properly validated before package creation; always use --validate-version or dpkg-deb --info to test. In complex automated build systems, it's common for version variables to be unquoted, causing word-splitting: always quote shell variables in package building scripts. If you see this error in CI/CD pipelines, the fix is usually in the build script's version variable assignment—ensure the version is hardcoded or properly captured from a single command with backticks (not single quotes). For packages coming from PPAs or third-party repositories, contact the maintainer to report the malformed version.
dpkg: serious warning: files list file for package 'package-name' contains empty filename
How to fix "files list file contains empty filename" in APT
E: Sub-process /usr/bin/dpkg returned an error code (2)
How to fix "Sub-process /usr/bin/dpkg returned an error code (2)" in APT
dpkg-divert: error: rename involves overwriting 'path' with different file
How to fix dpkg-divert rename conflicts in APT
E: Sub-process /usr/bin/dpkg returned an error code (1) during kernel installation
How to fix "dpkg returned an error code (1)" in APT kernel installation
dpkg: dependency problems prevent configuration of triggers
dpkg: dependency problems prevent configuration of triggers in apt