{"record":{"id":"1b5ae1a320550675","repo":"puppetlabs/puppet","slug":"failed-to-update-to-version-should-got-version","errorCode":null,"errorMessage":"Failed to update to version %{should}, got version %{version} instead","messagePattern":"Failed to update to version %(.+?), got version %(.+?) instead","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/package/apt.rb","lineNumber":182,"sourceCode":"      cmd << str\n    end\n    # rubocop:enable Style/RedundantCondition\n\n    unhold if properties[:mark] == :hold\n    begin\n      aptget(*cmd)\n    ensure\n      hold if @resource[:mark] == :hold\n    end\n\n    # If a source file was specified, we must make sure the expected version was installed from specified file\n    if source && !%i[present installed].include?(should)\n      is = query\n      raise Puppet::Error, _(\"Could not find package %{name}\") % { name: name } unless is\n\n      version = is[:ensure]\n\n      raise Puppet::Error, _(\"Failed to update to version %{should}, got version %{version} instead\") % { should: should, version: version } unless\n        insync?(version)\n    end\n  end\n\n  # What's the latest package version available?\n  def latest\n    output = aptcache :policy, @resource[:name]\n\n    if output =~ /Candidate:\\s+(\\S+)\\s/\n      Regexp.last_match(1)\n    else\n      err _(\"Could not find latest version\")\n      nil\n    end\n  end\n\n  #\n  # preseeds answers to dpkg-set-selection from the \"responsefile\"","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/package/apt.rb#L164-L200","documentation":"apt.rb:182: after installing from an explicit source file with a versioned ensure, the provider reads the installed version via query and calls insync?; if dpkg reports a version different from the requested one, it raises 'Failed to update to version %{should}, got version %{version} instead'. It is a post-install verification failure: apt-get ran, but the resulting package version does not satisfy ensure.","triggerScenarios":"package { X: ensure => '1.2.3', source => '...deb' } where the staged deb's Version: field is not 1.2.3 (e.g. Debian revision differences like 1.2.3-1 vs 1.2.3, or an epoch like 2:1.2.3), or apt resolved a different version from the repos because the source install was overridden.","commonSituations":"Setting ensure to the upstream tarball version while the deb carries a distro revision; epochs (1:...) omitted from ensure; the same package name available in a configured repo at another version and installed instead of the staged file; typo in the version string.","solutions":["Read the exact installed version from the message, then `dpkg-deb -f <source.deb> Version` and copy that string verbatim into ensure.","Account for Debian epochs and revisions in ensure (e.g. '1:2.0.1-1~bpo9+1' must match character-for-character what dpkg reports).","Ensure the source file really is the one being installed — if a repo version wins, remove the conflicting repo entry or pin the package."],"exampleFix":"# before\npackage { 'nginx': ensure => '1.18.0', source => '/tmp/nginx.deb' } # deb Version is 1.18.0-2\n\n# after\npackage { 'nginx': ensure => '1.18.0-2', source => '/tmp/nginx.deb' }","handlingStrategy":"validation","validationCode":"# ensure must equal dpkg-deb's Version exactly\nwant = '1.18.0'\nhave = `dpkg-deb -f /tmp/nginx.deb Version`.strip\nfail \"ensure version mismatch: wanted #{want}, deb has #{have}\" unless want == have","typeGuard":null,"tryCatchPattern":"begin\n  provider.install\nrescue Puppet::Error => e\n  raise unless e.message =~ /Failed to update to version/\n  installed = e.message[/got version (\\S+)/, 1]\n  resource[:ensure] = installed # adopt reality or fix the artifact; then re-run\nend","preventionTips":["Generate ensure strings from dpkg-deb -f <deb> Version in your packaging pipeline (epoch/revision included).","Never hand-type versions for source-based installs; copy them from dpkg-query.","Pin repo versions with apt preferences when both a repo and a staged deb could satisfy the name."],"tags":["puppet","apt","debian","packages","version-mismatch"],"backgroundTag":"package-version-mismatch","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}