{"id":1031,"date":"2025-02-10T10:59:06","date_gmt":"2025-02-10T09:59:06","guid":{"rendered":"https:\/\/www.streppone.it\/cosimo\/blog\/?p=1031"},"modified":"2025-02-10T21:59:06","modified_gmt":"2025-02-10T20:59:06","slug":"how-to-pin-a-specific-apt-package-version","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/","title":{"rendered":"How to pin a specific apt package version"},"content":{"rendered":"\n<p>I&#8217;d like to pin a specific package, say <code>redis-server<\/code>, to a specific version, in my case <code>7.0.*<\/code>, and that seems straight-forward to do with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Package: redis-server\nPin: version 7.0.*\nPin-Priority: 1001<\/code><\/pre>\n\n\n\n<p>Now, I would also like to have <code>apt<\/code> <strong>fail<\/strong> when 7.0.* is not available, either because there are only newer versions available, f.ex. 7.2.* or 7.4.* or perhaps because only older versions like 6.* are available.<\/p>\n\n\n\n<p>I can&#8217;t seem to find a way to achieve that. I&#8217;ve read various resources only, consulted <code>man 5 apt_preferences<\/code>, but I&#8217;m still not sure how to.<\/p>\n\n\n\n<p>I tried combining the previous pinning rule to another one with priority <code>-1<\/code>, as in the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Package: redis-server\nPin: release *\nPin-Priority: -1\n<\/code><\/pre>\n\n\n\n<p>But that seems to make all versions unavailable unfortunately. Here&#8217;s what I&#8217;m seeing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ apt-cache policy redis-server\nredis-server:\n  Installed: (none)\n  Candidate: 5:7.0.15-1build2\n  Version table:\n     5:7.0.15-1build2 500\n        500 &#91;http:\/\/no.archive.ubuntu.com\/ubuntu](http:\/\/no.archive.ubuntu.com\/ubuntu) noble\/universe amd64 Packages\n\n$ cat &gt; \/etc\/apt\/preferences.d\/redis-server\nPackage: redis-server\nPin: version 7.0.15*\nPin-Priority: 1001\n\nPackage: redis-server\nPin: release *\nPin-Priority: -1\n\n$ apt-cache policy redis-server\nredis-server:\n  Installed: (none)\n  Candidate: (none)\n  Version table:\n     5:7.0.15-1build2 -1\n        500 &#91;http:\/\/no.archive.ubuntu.com\/ubuntu](http:\/\/no.archive.ubuntu.com\/ubuntu) noble\/universe amd64 Packages<\/code><\/pre>\n\n\n\n<p>I expected this configuration to provide an available candidate, since one exists (7.0.15), but that doesn&#8217;t work.<\/p>\n\n\n\n<p>Note that a successful outcome for me is:<\/p>\n\n\n\n<ul>\n<li>define a target wanted version, f.ex. <code>redis-server=7.0.*<\/code><\/li>\n\n\n\n<li>provide an apt preferences.d file such that:\n<ul>\n<li>when any 7.0.* versions are available, apt will install that version<\/li>\n\n\n\n<li>when no 7.0.* versions are available, apt will <strong>fail<\/strong> installing nothing<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>A bad outcome is when redis-server is installed, but with a package version that <strong>does not<\/strong> match what I had specified as requirement (hence, different from 7.0.*).<\/p>\n\n\n\n<p>This is on Ubuntu 24.04, although there is nothing specific to 24.04 or Ubuntu here I would think.<\/p>\n\n\n\n<p>Any ideas?<\/p>\n\n\n\n<p>Posted on stackoverflow, let&#8217;s see! <a href=\"https:\/\/unix.stackexchange.com\/questions\/790837\/how-to-pin-an-apt-package-to-a-version-and-fail-if-its-not-available\">https:\/\/unix.stackexchange.com\/questions\/790837\/how-to-pin-an-apt-package-to-a-version-and-fail-if-its-not-available<\/a><\/p>\n\n\n\n<p><strong>UPDATE:<\/strong> based on the stackoverflow feedback, it seems that the solution wasn&#8217;t far off.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Package: redis-server\nPin: version 5:7.0.15*\nPin-Priority: 1001\n\nPackage: redis-server\nPin: release *\nPin-Priority: -1<\/code><\/pre>\n\n\n\n<p>I needed to prepend the version with the <code>\"5:<\/code>&#8220;. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;d like to pin a specific package, say redis-server, to a specific version, in my case 7.0.*, and that seems straight-forward to do with: Now, I would also like to have apt fail when 7.0.* is not available, either because there are only newer versions available, f.ex. 7.2.* or 7.4.* or perhaps because only older [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[460,248,343],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to pin a specific apt package version - Random hacking<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to pin a specific apt package version - Random hacking\" \/>\n<meta property=\"og:description\" content=\"I&#8217;d like to pin a specific package, say redis-server, to a specific version, in my case 7.0.*, and that seems straight-forward to do with: Now, I would also like to have apt fail when 7.0.* is not available, either because there are only newer versions available, f.ex. 7.2.* or 7.4.* or perhaps because only older [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-10T09:59:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-10T20:59:06+00:00\" \/>\n<meta name=\"author\" content=\"cosimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cosimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"How to pin a specific apt package version\",\"datePublished\":\"2025-02-10T09:59:06+00:00\",\"dateModified\":\"2025-02-10T20:59:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/\"},\"wordCount\":259,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"keywords\":[\"apt\",\"debian\",\"ubuntu\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/\",\"name\":\"How to pin a specific apt package version - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"datePublished\":\"2025-02-10T09:59:06+00:00\",\"dateModified\":\"2025-02-10T20:59:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to pin a specific apt package version\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\",\"name\":\"Random hacking\",\"description\":\"Assume nothing. Code defensively. Keep it simple, stupid!\",\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\",\"name\":\"cosimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"caption\":\"cosimo\"},\"logo\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to pin a specific apt package version - Random hacking","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/","og_locale":"en_US","og_type":"article","og_title":"How to pin a specific apt package version - Random hacking","og_description":"I&#8217;d like to pin a specific package, say redis-server, to a specific version, in my case 7.0.*, and that seems straight-forward to do with: Now, I would also like to have apt fail when 7.0.* is not available, either because there are only newer versions available, f.ex. 7.2.* or 7.4.* or perhaps because only older [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/","og_site_name":"Random hacking","article_published_time":"2025-02-10T09:59:06+00:00","article_modified_time":"2025-02-10T20:59:06+00:00","author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"How to pin a specific apt package version","datePublished":"2025-02-10T09:59:06+00:00","dateModified":"2025-02-10T20:59:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/"},"wordCount":259,"commentCount":0,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"keywords":["apt","debian","ubuntu"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/","name":"How to pin a specific apt package version - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"datePublished":"2025-02-10T09:59:06+00:00","dateModified":"2025-02-10T20:59:06+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2025\/02\/how-to-pin-a-specific-apt-package-version\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"How to pin a specific apt package version"}]},{"@type":"WebSite","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website","url":"https:\/\/www.streppone.it\/cosimo\/blog\/","name":"Random hacking","description":"Assume nothing. Code defensively. Keep it simple, stupid!","publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1","name":"cosimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","caption":"cosimo"},"logo":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/1031"}],"collection":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/comments?post=1031"}],"version-history":[{"count":3,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/1031\/revisions"}],"predecessor-version":[{"id":1034,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/1031\/revisions\/1034"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=1031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=1031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=1031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}