I am working on a Red Hat Enterprise Linux server where someone apparently fat-fingered a Python version cleanup and broke yum as a result. A colleague gathered that in order to fix that, you have to manually install the Python .rpm used by that particular version of yum, but since yum --version doesn't work, we have no way to know which version of yum is installed on that server. rpm -q yum doesn't work either, because yum appears to have been side-loaded on that server.

Is there any way to find the installed version other than with package manager commands?

  • 1
    If yum was installed outside the realm of package management, and the binary doesn't even work enough to have it tell you its version, hopefully you can find the shell history of the user who performed the install and will find the version number in (for example) the filename of the tarball which was extracted. – DopeGhoti Aug 31 '17 at 16:52
  • This sounds like a "nuke it from orbit" scenario. Sure, you can troubleshoot all the things they broke along the way, but after something so destructive do you really want to find out what other square blocks the previous admin shoved through round holes? – Centimane Aug 31 '17 at 18:50

Given what you've said, the only way I can think of is to look in the main Yum Python module. Python modules can be found in /usr/lib/python*. Under each of those directories, look in site-packages/yum/__init__.py for a line like the following:

__version__ = "3.2.27"

However, once you're that far, you technically know what Python version you need, because the Python module directories are versioned.

  • 3
    grep ^__version__ /usr/lib/python*/site-packages/yum/__init__.py – Jeff Schaller Aug 31 '17 at 17:34
  • Excellent point, hadn't thought of just writing it up as a single command. – Austin Hemmelgarn Aug 31 '17 at 17:35
  • feel free to steal it; I'll delete my comments when you're done – Jeff Schaller Aug 31 '17 at 17:36
  • Eh, you deserve the credit, and putting it in a single command bypasses the aspect of seeing which Python directory has the Yum module being a quicker way to figure out what the OP really wants (namely, the Python version he needs to reinstall). – Austin Hemmelgarn Aug 31 '17 at 17:40
  • then make it grep -l ...? I'm happy to have it incorporated into your answer; I was going to write one up, but you beat me to it. -- sorry, grep -H – Jeff Schaller Aug 31 '17 at 17:41

You need the full NVR to find the real version, 3.x.x isn't good enough to know wtf you have. But assuming you didn't delete random things then the yum history DB will still be there. So you can run:

# sqlite3 /var/lib/yum/history/history-*.sqlite \
  "SELECT * FROM vtrans_data_pkgs WHERE name = 'yum';"

...or you can even download yum from github and run "./yummain.py history" ot get the nice UI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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