How to compare Debian package versions?

后端 未结 3 1164
鱼传尺愫
鱼传尺愫 2020-12-24 07:26

I looked at python-apt and python-debian, and they don\'t seem to have functionality to compare package versions. Do I have to write my own, or is

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 07:37

    Perhaps because the title doesn't mention Python (though the tags do), Google brought me here when asking the same question but hoping for a bash answer. That seems to be:

    $ dpkg --compare-versions 11a lt 100a && echo true
    true
    $ dpkg --compare-versions 11a gt 100a && echo true
    $ 
    

    To install a version of rubygems that's at least as new as the version from lenny-backports in a way that gives no errors on lenny and squeeze installations:

    sudo apt-get install rubygems &&
    VERSION=`dpkg-query --show --showformat '${Version}' rubygems` &&
    dpkg --compare-versions $VERSION lt 1.3.4-1~bpo50+1 &&
    sudo apt-get install -t lenny-backports rubygems
    

    Perhaps I should have asked how to do that in a separate question, in the hope of getting a less clunky answer.

提交回复
热议问题