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.12-1.80.el6_3.5.i686
How do I do a check in BASH?
Do I do something like?
if [ "$(rpm -qa | grep glibc-static)" != "" ] ; then
And what do I need to use for other distributions? apt-get?
The dpkg-query command can be used to show if a specific package is installed in your system. To do it, run dpkg-query followed by the -l flag and the name of the package you want information about.
Start the Anaconda Navigator application. Select Environments in the left column. A dropdown box at the center-top of the GUI should list installed packages. If not, then select Installed in the dropdown menu to list all packages.
Start R within your package directory, load the devtools library with library(devtools) and then type check() , just as you had used build() and install() to build and install the package.
Try the following code :
if ! rpm -qa | grep -qw glibc-static; then yum install glibc-static fi
or shorter :
rpm -qa | grep -qw glibc-static || yum install glibc-static
For debian likes :
dpkg -l | grep -qw package || apt-get install package
For archlinux :
pacman -Qq | grep -qw package || pacman -S package
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With