Zypper install specific major version without specifying the minor version

opensusepackage-managementzypper

I am writing a script that installs some packages and does some configuration work. I want the script to install a specific major version of a package, but I do not care which minor version of the package it is.

More to the point, I want it to install the latest 2.y.z release of the package, but not 1.y.z or 3.y.z (or any other major version number).

I have tried (without success)

  • zypper install 'mypackage=2'
  • zypper install 'mypackage>1<3'
  • zypper install 'mypackage>1' 'mypackage<3'
  • zypper install 'mypackage>=2.0.0' 'mypackage<3.0.0'

The last one seems promising, because then zypper complains:

'mypackage>=2.0.0' not found in package names. Trying capabilities. No
provider of 'mypackage >= 2.0.0' found.

However, after that message, it still proceeds with installing mypackage-1.5.0, because that satisfies the second package-edition specified.

Best Answer

Better

At first I experimented with SailorCire's answer here and came up with an improved version:

zypper search -t package -x -s PACKAGE | grep " MIN_NUM" | cut -d '|' -f 4 | tr -d '[:space:], then you can pipe it into zypper install by doing zypper install PACKAGE followed by backticks-surrounded command above.

For example, this will install php7-pear 1.*:

zypper -n in --details php7-pear-`zypper search -t package -x -s php7-pear | grep " 1." | cut -d '|' -f 4 | tr -d '[:space:]'`

Best

But then I came up with a better solution. Rather than target a specific version with hacks like this, we can exclude versions without hacks using zypper addlock with version constraints.

So, what OP wants is actually this:

zypper addlock "mypackage < 2"
zypper addlock "mypackage >= 3"

These will prevent mypackage installs with versions <2 or >=3.