Offline package installs using dpkg and apt-get (Ubuntu/Debian/etc)

apt-get logo

More often than not, I have to deploy a system which will not have access to the internet or an apt-proxy/apt-cacher installations somewhere. This means I cannot install new packages which might be required at a later stage.

I’ll use an example install of postgresql to explain how you can get all the required files (specifically for your machine) and deploy it on your server.

For a VERY quick run through on a single machine, check out the following video I made:

In the following example

  • internet-srv has internet access
  • lockdown-srv has no internet access and requires an installation of PostgreSQL

Pay close attention to which server is used to do what

Step 1: On lockdown-srv:

# Navigate to /var/tmp
hendri@lockdown-srv:~$ cd /var/tmp
# Get a list of download locations for all packages required for PostgreSQL on lockdown-srv
hendri@lockdown-srv:/var/tmp$ sudo apt-get --allow-unauthenticated -y install --print-uris postgresql | cut -d\' -f2 | grep http:// > /var/tmp/download-list
# Here's an example of what the applicable file can contain:
hendri@lockdown-srv:/var/tmp$ cat download-list
# Next, you need to copy/move the 'download-list' file to a machine with access to the internet. In this example, we'll use internet-srv
hendri@lockdown-srv:/var/tmp$ scp download-list hendri@internet-srv:/var/tmp/

Step 2: On internet-srv:

# Navigate to /var/tmp
hendri@internet-srv:~$ cd /var/tmp
# Check that the download-list file is there
hendri@internet-srv:~$ ls -al
total 624
drwxrwxrwt  2 root   root      4096 Sep 30 23:53 .
drwxr-xr-x 13 root   root      4096 Sep  5 00:56 ..
-rw-rw-r--  1 hendri hendri     624 Sep 30 23:52 download-list
# Download the required files
hendri@internet-srv:~$ wget -i download-list
--2014-09-30 23:52:36--
Resolving (,,, ...
<!------- SOME OUTPUT OMMITTED -------!>
100%[========================================================================================================================================>] 5,088       --.-K/s   in 0s      
2014-09-30 23:53:01 (622 MB/s) - ‘postgresql_9.3+154_all.deb’ saved [5088/5088]
FINISHED --2014-09-30 23:53:01--
Total wall clock time: 24s
Downloaded: 6 files, 3.5M in 23s (158 KB/s)
# Copy the *.deb files that were downloaded back to 'lockdown-srv'
hendri@internet-srv:~$ scp *.deb hendri@lockdown-srv:/var/tmp/

Step 3: On lockdown-srv:

# Install the packages required for PostgreSQL
hendri@lockdown-srv:~$ sudo dpkg -i *.deb
Selecting previously unselected package libpq5.
(Reading database ... 63448 files and directories currently installed.)
Preparing to unpack libpq5_9.3.5-0ubuntu0.14.04.1_amd64.deb ...
Unpacking libpq5 (9.3.5-0ubuntu0.14.04.1) ...
Selecting previously unselected package postgresql.
Preparing to unpack postgresql_9.3+154_all.deb ...
Unpacking postgresql (9.3+154) ...
Selecting previously unselected package postgresql-9.3.
Preparing to unpack postgresql-9.3_9.3.5-0ubuntu0.14.04.1_amd64.deb ...
Unpacking postgresql-9.3 (9.3.5-0ubuntu0.14.04.1) ...
Selecting previously unselected package postgresql-client-9.3.
Preparing to unpack postgresql-client-9.3_9.3.5-0ubuntu0.14.04.1_amd64.deb ...
Unpacking postgresql-client-9.3 (9.3.5-0ubuntu0.14.04.1) ...
Selecting previously unselected package postgresql-client-common.
Preparing to unpack postgresql-client-common_154_all.deb ...
Unpacking postgresql-client-common (154) ...
Selecting previously unselected package postgresql-common.
Preparing to unpack postgresql-common_154_all.deb ...
Adding 'diversion of /usr/bin/pg_config to /usr/bin/pg_config.libpq-dev by postgresql-common'
Unpacking postgresql-common (154) ...
Setting up libpq5 (9.3.5-0ubuntu0.14.04.1) ...
Setting up postgresql-client-common (154) ...
Setting up postgresql-common (154) ...
Adding user postgres to group ssl-cert
Creating config file /etc/logrotate.d/postgresql-common with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
 * No PostgreSQL clusters exist; see "man pg_createcluster"
Setting up postgresql-client-9.3 (9.3.5-0ubuntu0.14.04.1) ...
update-alternatives: using /usr/share/postgresql/9.3/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Processing triggers for ureadahead (0.100.0-16) ...
Setting up postgresql-9.3 (9.3.5-0ubuntu0.14.04.1) ...
Creating new cluster 9.3/main ...
  config /etc/postgresql/9.3/main
  data   /var/lib/postgresql/9.3/main
  locale en_US.UTF-8
  port   5432
update-alternatives: using /usr/share/postgresql/9.3/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
 * Starting PostgreSQL 9.3 database server                                                                                                                                 [ OK ] 
Setting up postgresql (9.3+154) ...
Processing triggers for man-db ( ...
Processing triggers for libc-bin (2.19-0ubuntu6.3) ...

That’s it. You’ve just installed PostgreSQL on a server with no connection to the internet.

You can obviously use any other method to download the files in ‘download-list’. This is just one method.

Add a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


  1. melissa

    How to download a particular version of Postgresql, for example postgresql-12. When I run “sudo apt-get –allow-unauthenticated -y install –print-uris postgresql | cut -d\’ -f2 | grep http:// > /var/tmp/download-list”, it automatically leads me to postgresql 10, but I am looking for 12.

  2. Innk

    which font did you used to make this letters?