Checking for installed packages and if not found install

前端 未结 4 541
野趣味
野趣味 2021-02-01 20:01

I need to check for installed packages and if not installed install them.

Example for RHEL, CentOS, Fedora:

rpm -qa | grep glibc-static
glibc-static-2.1         


        
4条回答
  •  眼角桃花
    2021-02-01 20:48

    Based on @GillesQuenot and @Kidbulra answers, here's an example how to loop over multiple packages, and install if missing:

    packageList="git gcc python-devel"
    
    for packageName in $packageList; do
      rpm --quiet --query $packageName || sudo yum install -y $packageName
    done
    

提交回复
热议问题