Ubuntu – Download and install ubuntu packages and dependencies on a server without internet connection

offlinepackage-management

I'm trying to download all packages and needed dependencies on a server with working internet connection and transfer them on server without internet connection and then install them via apt-get.

I have two solutions to download packages:

  1. apt-get --print-uris --yes install pkgspec | grep ^\' | cut -d\' -f2 > downloads.list
    

Is useless because it works only for packages and dependencies that are not downloaded and installed already on a server with working internet connection.

  1. aptitude download '?reverse-depends(package)'
    

It downloads all packages and dependencies also if you don't need them.

Anyone knows a better solution to download a package and dependencies needed to be installed on a fresh install of Ubuntu server 16.04?

I want to create a script that goes trough a list of packages and downloads all packages and dependencies automatically.

Then I need a solution to use this packages on a offline computer with apt-get. Idea is to create a local apt repository that allows you to use your local packages via apt-get.

So I use this command to create Packages.gz that contains info about all packages that were download in first step.

dpkg-scanpackages . /dev/null | gzip > Packages.gz

Then I add a new source to /etc/apt/sources.list.d/ and run apt-get update.

deb [trusted=yes] file:///tmp/dpkgs /

Now I have a problem that I can for example install apache (still some errors). But if I want to install php I got the following error.

root@ubuntu:~# apt-get install php
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 php : Depends: php7.0 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Anyone has a working solution for this problem?
Thanks.

Best Answer

Lan Morrison has made an isorespin.sh script that will make an image from commands you give and with an added command can have all the updates to that time on the image and install any apt install you want on the install image it makes. I used it and it works real good.

For more details, see: Customizing Ubuntu ISOs: Documentation and examples of how to use isorespin.sh.

Related Question