12

I want to install a rpm package, (e.g. python 3), and all of its dependencies in a linux server that does not have internet connection.

How can I do that?

Chaminda Bandara
  • 2,067
  • 2
  • 28
  • 31
Raul Mercado
  • 324
  • 1
  • 4
  • 14
  • [How to use yum to get all RPMs required, for offline use?](https://unix.stackexchange.com/q/259640/56041) and friends. – jww Apr 23 '19 at 15:00

3 Answers3

9

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
  • FYI if you get "yumdownloader: command not found" you can install it with: `yum install yum-utils` – degenerate Feb 01 '23 at 22:20
  • This does not work for in me CentOS 7 even with the specified docker-ce package. It does not download any dependent images but only the docker-ce package. However, this answer did work for me: https://unix.stackexchange.com/a/260261/221435 – TerekC Jun 22 '23 at 15:42
7

Assuming you already downloaded the package before from another machine that has internet access and FTP the files to your server, you can use the following command to install a rpm

rpm -ivh package_name_x85_64.rpm

options:

  • i = This installs a new package.
  • v = Print verbose information
  • h = Print 50 hash marks as the package archive is unpacked.

You can also check the rpm manual for more options and details

Cedric Guindon
  • 354
  • 1
  • 12
2

There is a way, but it is quite tricky and might mess up your servers, so be very careful.

Nomenclature:

  • online : your system that is connected to the repositories
  • offline: your system that is not connected

Steps:

Compress your rpm database from the offline system and transfer it to the online system:

cd /var/lib/rpm/
tar -cvzf /tmp/rpmdb.tgz *
scp /tmp/rpmdb.tgz root@online:/tmp

on your online system; replace your rpm db with the one from the offline system:

cp -r /var/lib/rpm{,.bak} # back up your rpmdb from your online system. Make sure not to lose this!!
rm -rf /var/lib/rpm/*
cd /var/lib/rpm
tar -xvf /tmp/rpmdb.tgz # now your online system pretends to have the rpm database from the offline system. Don't start really installing / uninstalling rpms or you'll break everything

now simulate your update with download-only (I didn't run this with yum but with zypper, but it should be similar):

zypper up --download-only

Now you can fetch all the downloaded packages and they should suffice for updating your offline system

And now restore your online machine:

rm -rf /var/lib/rpm
cp -r /var/lib/rpm{.bak,}
Chris Maes
  • 35,025
  • 12
  • 111
  • 136