How to install a rpm package and its dependencies offline

后端 未结 2 828
庸人自扰
庸人自扰 2021-01-22 17:17

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?

2条回答
  •  被撕碎了的回忆
    2021-01-22 17:59

    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,}
    

提交回复
热议问题