CentOS / RHEL: yum Command Reinstall Package

See all Redhat/CentOS/Fedora Core related FAQ
I accidental deleted the configuration file stored in /etc/ directory and the latest backup were made yesterday. How do I reinstall the package using the yum command under RHEL / CentOS Linux server?

You can use the yum command with reinstall option. This will reinstall the identically versioned package as is currently installed.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category Package Manager
OS compatibility AlmaLinux Fedora RHEL Rocky Stream
Est. reading time 2 minutes

CentOS / RHEL: yum Command Reinstall Package Command

The syntax is as follows:
yum reinstall packageName
yum reinstall packageName1 packageName2

Let us see some example for the latest version of Fedora, CentOS, RHEL and friends to reinstall a package.


In this example reinstall a package called keepalived, type:
# yum reinstall keepalived
Here is what I see:

Loaded plugins: product-id, rhnplugin, subscription-manager
Updating certificate-based repositories.
Setting up Reinstall Process
Resolving Dependencies
--> Running transaction check
---> Package keepalived.x86_64 0:1.2.2-2.el6 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

 Package                             Arch                            Version                                 Repository                     Size
 keepalived                          x86_64                          1.2.2-2.el6                             epel                          147 k

Transaction Summary
Reinstall     1 Package(s)

Total download size: 147 k
Installed size: 380 k
Is this ok [y/N]: y
Downloading Packages:
keepalived-1.2.2-2.el6.x86_64.rpm                                                                                         | 147 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : keepalived-1.2.2-2.el6.x86_64                                                                                                 1/1 
Installed products updated.

  keepalived.x86_64 0:1.2.2-2.el6                                                                                                                
This does not work for “installonly” packages such as RHEL kernels packages.

Summing up

We pass the reinstall or rei option to the yum command to reinstall given package names. It will install the specified packages, fails if some of the packages are either not installed or not available when there is no repository where to download the same RPM. The syntax is:
# yum reinstall pkg
# 'rei' is an alias for 'reinstall' #
# yum rei pkg1 pkg2

Want to read more about the yum command? Try reading the following manual pages using the man command or --help option as follows on your CentOS, RHEL, Alma or Rocky Linux:
$ man yum
$ yum --help

You can filter out info using the grep command or egrep command too:
$ yum --help | grep -- install
Here is what I see:

autoremove                remove all unneeded packages that were originally installed as dependencies
distro-sync               synchronize installed packages to the latest available versions
install                   install a package or packages on your system
mark                      mark or unmark installed packages as installed by user.
reinstall                 reinstall a package
swap                      run an interactive YUM mod for remove and install one spec
debug-dump                dump information about installed rpm packages to file
debuginfo-install         install debuginfo packages
  --installroot [path]  set install root
  --nodocs              do not install documentations
  --allowerasing        allow erasing of installed packages to resolve

I hope this helps fellow developers or sysadmin to fix the issue. Does this option works with the dnf? Yes, see the dnf reinstall command faq for more info.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

3 comments… add one
  • ron Dec 31, 2011 @ 4:17

    this is from fedora 16:


    clean_requirements_on_remove = 1

    # This is the default, if you make this bigger yum won’t see if the metadata
    # is newer on the remote and so you’ll “gain” the bandwidth of not having to
    # download the new metadata and “pay” for it by yum not having correct
    # information.
    # It is esp. important, to have correct metadata, for distributions like
    # Fedora which don’t keep old packages around. If you don’t like this checking
    # interupting your command line usage, it’s much better to have something
    # manually check the metadata once an hour (yum-updatesd will do this).
    # metadata_expire=90m

    # PUT YOUR REPOS HERE OR IN separate files named file.repo
    # in /etc/yum.repos.d


  • amir tal Nov 4, 2012 @ 12:22

    this does not work.
    yum does not have such an option “reinstall”

    usage: yum [options]

    -h, –help show this help message and exit
    -t, –tolerant be tolerant of errors
    -C run entirely from cache, don’t update cache
    -c [config file] config file location
    -R [minutes] maximum command wait time
    -d [debug level] debugging output level
    -e [error level] error output level
    -q, –quiet quiet operation
    -v, –verbose verbose operation
    -y answer yes for all questions
    –version show Yum version and exit
    –installroot=[path] set install root
    –enablerepo=[repo] enable one or more repositories (wildcards allowed)
    –disablerepo=[repo] disable one or more repositories (wildcards allowed)
    -x [package], –exclude=[package]
    exclude package(s) by name or glob
    disable exclude from main, for a repo or for
    –obsoletes enable obsoletes processing during updates
    –noplugins disable Yum plugins
    –nogpgcheck disable gpg signature checking
    disable plugins by name

    nope.. no reinstall here…

  • amir tal Nov 4, 2012 @ 12:23

    nevermind… thats an old version…

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.