How to fix dpkg: error: version string has embedded spaces in APT

APTINTERMEDIATEHIGHUpdated Dec 29, 2025· 135 views

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.

Quick fix

Fixes dpkg: error: version string has embedded spaces

sudo apt update
  1. Identify the problematic package
  2. Check if using a custom local .deb file
  3. Inspect package metadata if from system repository
  4. Fix custom .deb file source
apt — error
sudo apt update
dpkg: error: version string has embedded spaces

What this error means

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.

Typical symptoms

  • dpkg command fails with "version string has embedded spaces" error during package installation
  • Error appears after running apt update, apt install, or during package configuration
  • The error message shows the actual problematic version string (e.g., "version 'uname -r'...")
  • Package installation is interrupted and leaves the system in a broken state
  • update-initramfs or similar triggers fail during kernel or system updates

Common causes

  1. Shell script using single quotes instead of backticks for command substitution: 'uname -r' instead of `uname -r`
  2. Manually edited package control file (usually in a custom .deb) with spaces in the Version field
  3. Broken package installation interrupted mid-process, leaving corrupted package metadata
  4. Custom or third-party .deb package with invalid Version field that does not follow Debian format
  5. Package postinstall script with syntax errors in version comparison logic
  6. Corrupted /var/lib/dpkg/status or /var/lib/dpkg/available files from failed updates

How to fix "dpkg: error: version string has embedded spaces"

1Identify the problematic package

First, determine which package is causing the error. Run the command that triggers the error and note the exact error message:

bash
sudo apt update

Or if installing a specific package:

bash
sudo apt install package-name

The error message will show the exact version string with spaces. For example:

bash
dpkg: error: version 'uname -r' has bad syntax: version string has embedded spaces

This tells you the version field contains the literal string "uname -r" (with a space) instead of the kernel version.

2Check if using a custom local .deb file

If you are installing a local .deb file you created or downloaded, extract and inspect its control file:

bash
cd /tmp
ar x /path/to/package.deb
tar -xzf control.tar.gz
cat control

Look for the Version field:

bash
Package: mypackage
Version: 1.0.0
Architecture: amd64

The 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.

3Inspect package metadata if from system repository

If the error comes from a system package (from apt repositories), check the dpkg database:

bash
sudo cat /var/lib/dpkg/status | grep -A 20 "Package: problematic-package-name"

Look at the Version line. It should be clean without spaces:

bash
Version: 1.2.3-4~ubuntu1

If it shows something like "Version: uname -r" or has embedded spaces, the package metadata is corrupted.

You can also query installed packages:

bash
dpkg -l | grep problematic-package
4Fix custom .deb file source

If you are building your own .deb package, check your debian/control or debian/rules file. Look for any backtick issues:

Wrong (using single quotes):

bash
echo "Version: 'uname -r'" > control

Correct (using backticks):

bash
echo "Version: $(uname -r)" > control

Or better, hardcode the version:

bash
echo "Version: 5.15.0-56-generic" > control

Rebuild the .deb file:

bash
cd /path/to/package
dpkg-deb --build . ../package.deb

Then test installation:

bash
sudo dpkg -i ../package.deb
5Validate version string format

Use dpkg's built-in validation to check if a version string is valid (requires dpkg 1.18.16+):

bash
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:

bash
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.

6Fix corrupted system package metadata

If the error comes from a system package and is due to corruption in /var/lib/dpkg/status:

bash
# Create a backup first
sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.backup

# Reconfigure packages
sudo dpkg --configure -a

If a specific package is broken:

bash
# Remove the broken package
sudo dpkg --remove --force-remove-reinstreq broken-package-name

# Reinstall it
sudo apt install --reinstall broken-package-name

If corruption is severe:

bash
# Clear the available database and rebuild
sudo dpkg --clear-avail
sudo apt update

# Reconfigure all packages
sudo dpkg --configure -a
7Verify fix with apt operations

After fixing the version string or package metadata, test that dpkg accepts it:

bash
sudo apt update

If installing a specific package:

bash
sudo dpkg -i /path/to/fixed-package.deb

Or using apt:

bash
sudo apt install package-name

Check package status:

bash
dpkg -l | grep package-name
sudo dpkg -s package-name

If the error still occurs, double-check the version field one more time:

bash
dpkg -I /path/to/package.deb | grep Version

The version must be a single string with no spaces.

Advanced notes

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.

Frequently asked questions

What does "dpkg: error: version string has embedded spaces" mean?
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.
How do I fix "dpkg: error: version string has embedded spaces"?
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.
What causes "dpkg: error: version string has embedded spaces"?
Shell script using single quotes instead of backticks for command substitution: 'uname -r' instead of uname -r Manually edited package control file (usually in a custom .deb) with spaces in the Version field Broken package installation interrupted mid-process, leaving corrupted package metadata
Is the "dpkg: error: version string has embedded spaces" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading