How to make rpm auto install dependencies
Create a (local) repository and use yum
to have it resolve the dependencies for you.
The CentOS wiki has a nice page providing a how-to on this. CentOS wiki HowTos/CreateLocalRepos.
Summarized and further minimized (not ideal, but quickest):
- Create a directory for you local repository, e.g.
/home/user/repo
. - Move the RPMs into that directory.
Fix some ownership and filesystem permissions:
# chown -R root.root /home/user/repo
Install the
createrepo
package if not installed yet, and run# createrepo /home/user/repo
# chmod -R o-w+r /home/user/repoCreate a repository configuration file, e.g.
/etc/yum.repos.d/myrepo.repo
containing[local]
name=My Awesome Repo
baseurl=file:///home/user/repo
enabled=1
gpgcheck=0Install your package using
# yum install packagename
when creating RPM package, how to auto install dependencies
You can't do it directly, you cannot install another RPM from within your RPM spec file.
The normal way, which you should follow, is to make your RPM depends on the other RPMs it needs, e.g. by adding this to your .spec file:
Requires: gcc, mysql-server, mysql-devel
When you then try to install your rpm with the rpm command:
rpm -ivh yourrpm-1.0.0.rpm
it will fail and tell you which packages to install, and you have to install those packages manually first.
Or you can use yum to install your rpm file:
yum install ./yourrpm.1.0.0.rpm
and yum will download and install the required dependencies before it installs your RPM package.
Automatically install build dependencies prior to building an RPM package
You can use the yum-builddep
command from the yum-utils
package to install all the build dependencies for a package.
The arguments can either be paths to spec files, paths to source RPMs or the names of packages which exist as source RPMs in a configured repository, for example:
yum-builddep my-package.spec
or
yum-builddep my-package.src.rpm
The same thing can be achieved on newer versions of Fedora that use dnf
as their package manager by making sure that dnf-plugins-core
is installed and then doing:
dnf builddep my-package.spec
or
dnf builddep my-package.src.rpm
How to install a rpm package and its dependencies offline
In CentOS/RedHat you can use yumdownloader
for specific packages, this downloads all RPMs required, then, compress the directory, upload it to the server without Internet access and install RPMs.
Here you can find and example, installing Kubernetes without Internet access.
yumdownloader --assumeyes --destdir=/var/rpm_dir/docker-ce --resolve docker-ce
tar -czvf d4r-k8s.tar.gz /var/rpm_dir
# Upload files
scp d4r-k8s.tar.gz root@YOUR-IP:/root
# Connect to your server
ssh root@YOUR-IP
tar -xzvf /root/d4r-k8s.tar.gz -C /
# install Docker:
yum install -y --cacheonly --disablerepo=* /var/rpm_dir/docker-ce/*.rpm
Make rpm package without any dependencies. However when the rpm package is installed in the environment, there is a problem of missing dependencies
What you're looking for is to disable the internal dependency generator:
%global _use_internal_dependency_generator 0
That said, your binary will not work unless you make sure those libraries are somehow accessible to it.
If you want it to have no dependency and not ship the libraries inside the package, you need to build it statically. E.g. -static
option for gcc
.
Provide dependencies of RPM for offline install
You can't do what you're asking in %pre
and %post
, because (a) those are executed at install time which is well after dependency resolution and (b) you wouldn't be able to call rpm
to install things from your %pre
because the database is locked for the transaction you are part of.
When I've done something like this in the past, I have found the easiest thing to do is to put all the RPMs in a single directory on the media and instruct the deployment team to yum localinstall *rpm
from that directory. If some of the third-party RPMs are older than what is installed, it will just skip over them.
Install other dependency rpm during the rpm installation
You cannot manipulate the RPM database in scriptlets. You need to put Requires: java-11-openjdk
and then provide the RPM in the same manner as your own software, e.g. yum
/dnf
repository, burned to a CD, etc.
Related Topics
Cmd 2>&1 > Log VS Cmd > Log 2>&1
Sed Command with -I Option (In-Place Editing) Works Fine on Ubuntu But Not MAC
Redirect All Output to File Using Bash on Linux
What Does "Bash:No Job Control in This Shell" Mean
Centos Through a Vm - No Urls in Mirrorlist
Script to Change Password on Linux Servers Over Ssh
How to Write Integer to Binary File Using Bash
Executing a Bash Script Upon File Creation
Why Can't You Sleep While Holding Spinlock
How to Count the Number of Characters in a Bash Variable
Get MAC Address Using Shell Script
Create New File But Add Number If Filename Already Exists in Bash
Ld: Using -Rpath,$Origin Inside a Shared Library (Recursive)
Convert Bash 'Ls' Output to JSON Array
What Occurs When a File Is 'Source'-D in Unix/Linux Context
Is There an Equivalent to Com on *Nix Systems ? If Not, What Was the *Nix Approach to Re-Usability