9

I need to get the version number of an rpm file like "foo-[RELEASE].rpm"

I tried these commands

rpm -q --queryformat '%{VERSION}' foo-[RELEASE].rpm 
package foo-[RELEASE].rpm is not installed

rpm -qp --queryformat "[%{VERSION}\n]" foo-[RELEASE].rpm

I need to replace the [RELEASE] placeholder with the version number.

2 Answers 2

20

Taking an example of sbt.rpm, here is how you may want to extract the information. Note that the package filename itself doesn't show the version and release information.

Get full package name:

$ rpm -qp sbt.rpm
sbt-0.12.2-1.noarch

Get NAME, VERSION, RELEASE and ARCHITECTURE separately:

$ rpm -qp --queryformat '%{NAME}' sbt.rpm
sbt

$ rpm -qp --queryformat '%{VERSION}' sbt.rpm
0.12.2

$ rpm -qp --queryformat '%{RELEASE}' sbt.rpm
1

$ rpm -qp --queryformat '%{ARCH}' sbt.rpm
noarch

Get NAME, VERSION, RELEASE and ARCHITECTURE combined:

$ rpm -qp --queryformat '%{NAME}-%{VERSION}-%{RELEASE}-%{ARCH}' sbt.rpm
sbt-0.12.2-1-noarch

Get only NAME, VERSION:

$ rpm -qp --queryformat '%{NAME}-%{VERSION}' sbt.rpm
sbt-0.12.2
4
  • Thanks for responding tuxdna, but it didn't work. Not getting any output
    – nakeer
    Commented Feb 2, 2014 at 8:13
  • I am using RPM version 4.11.1 on Fedora release 20. Perhaps that might make a difference. Also, can you update in question what commands you tried this time?
    – tuxdna
    Commented Feb 2, 2014 at 9:44
  • I tried all the commands suggested by you and not getting any output. I'm using RPM version 4.8.0 and centOS 6.4
    – nakeer
    Commented Feb 4, 2014 at 19:30
  • Thanks tuxdna, the problem is not with the commands but its with the rpm file. I tried with a different rpm file and the commands are working.
    – nakeer
    Commented Feb 4, 2014 at 19:37
3
 rpm -qip foo.rpm

shows version number :

Version     : 1.3.4

Not the answer you're looking for? Browse other questions tagged or ask your own question.