Install oracle-java7-installer through apt-cacher-ng

I've added the oracle-java7-installer ppa to my apt-cacher-ng server and to my clients. I cannot get it to install.

Any ideas on how I can do this? I think it fails when it tries to download the installation from Oracle. This is what happens when I try to install it:

admin@vgjs001:~$ sudo apt-get install oracle-java7-installer
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  gsfonts gsfonts-x11 java-common libfontenc1 libxfont1 x11-common xfonts-encodings xfonts-utils
Suggested packages:
  default-jre equivs binfmt-support visualvm ttf-baekmuk ttf-unfonts ttf-unfonts-core ttf-kochi-gothic
  ttf-sazanami-gothic ttf-kochi-mincho ttf-sazanami-mincho ttf-arphic-uming firefox firefox-2 iceweasel
  mozilla-firefox iceape-browser mozilla-browser epiphany-gecko epiphany-webkit epiphany-browser galeon midbrowser
  moblin-web-browser xulrunner xulrunner-1.9 konqueror chromium-browser midori google-chrome
The following NEW packages will be installed:
  gsfonts gsfonts-x11 java-common libfontenc1 libxfont1 oracle-java7-installer x11-common xfonts-encodings
  xfonts-utils
0 upgraded, 9 newly installed, 0 to remove and 10 not upgraded.
Need to get 4 269 kB/4 347 kB of archives.
After this operation, 7 548 kB of additional disk space will be used.
Do you want to continue [Y/n]? 
Get:1 "hyperlink-1" "repo-1" gsfonts all 1:8.11+urwcyr1.0.7~pre44-4.2ubuntu1 [3 374 kB]
Get:2 "hyperlink-2" "repo-2"  libfontenc1 amd64 1:1.1.0-1 [15,4 kB]                         
Get:3 "hyperlink-3" "repo-3"  libxfont1 amd64 1:1.4.4-1 [133 kB]                            
Get:4 "hyperlink-4" "repo-4"  x11-common all 1:7.6+12ubuntu1 [57,7 kB]                      
Get:5 "hyperlink-5" "repo-5"  xfonts-encodings all 1:1.0.4-1ubuntu1 [583 kB]                
Get:6 "hyperlink-6" "repo-6"  xfonts-utils amd64 1:7.6+1 [96,4 kB]                          
Get:7 "hyperlink-7" "repo-7"  gsfonts-x11 all 0.22 [9 108 B]                                
Fetched 3 232 kB in 33s (95,1 kB/s)                                                                                   
Preconfiguring packages ...
Selecting previously unselected package java-common.
download failed
Oracle JDK 7 is NOT installed.
dpkg: error processing oracle-java7-installer (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up gsfonts (1:8.11+urwcyr1.0.7~pre44-4.2ubuntu1) ...
Setting up libfontenc1 (1:1.1.0-1) ...
Setting up libxfont1 (1:1.4.4-1) ...
Setting up x11-common (1:7.6+12ubuntu1) ...
Setting up xfonts-encodings (1:1.0.4-1ubuntu1) ...
Setting up xfonts-utils (1:7.6+1) ...
Setting up gsfonts-x11 (0.22) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Errors were encountered while processing:
 oracle-java7-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)

I was just battling with this, here are my findings for Ubuntu 14.04 Trusty Tahr.

The installer uses apt-config to determine which proxy to use. Specifically if Acquire::http::Proxy::download.oracle.com returns DIRECT to determine whether to use the default proxy of to download directly.

Specifically the install runs

# use apt proxy
APT_PROXIES=$(apt-config shell \
http_proxy Acquire::http::Proxy \
https_proxy Acquire::https::Proxy \
ftp_proxy Acquire::ftp::Proxy \
dl_direct Acquire::http::Proxy::download.oracle.com \
)

And later on

if [ "$dl_direct" = "DIRECT" ]; then
    unset http_proxy
    unset https_proxy
    unset ftp_proxy
fi

If you use the following apt config then the installer with download directly:

Acquire::http::Proxy "http://my.proxy.com:3142";
Acquire::http::Proxy {
        download.oracle.com DIRECT;
};

While this works it is somewhat annoying as the download takes forever and that somewhat defeats the purpose of the proxy.

I found that the installer checks a debconf variable to check whether to use a local file. The property checked is oracle-java8-installer/local and it is a string.

Specifically the installer runs:

db_get oracle-java8-installer/local
if [ -d "$RET" -a -f "$RET"/$FILENAME ]; then

    echo "Installing from local file $RET/$FILENAME"
    cp -f -p "$RET"/$FILENAME ${FILENAME}_TEMP
    mv -f ${FILENAME}_TEMP $FILENAME
else # no local file

So if you have the JDK downloaded and in a directory /jdk/dir then you need to run the following command before running the installer:

sudo debconf-set-selections <<< 'debconf oracle-java8-installer/local string /jdk/dir/'

Note the trailing / on the directory - this is required.


I ran against the same issue, but managed to find a workaround. The main issue is that apt-cacher-ng does not forward any custom HTTP headers, as used by the Oracle installer (wget) to accept the Oracle license.

I've made the following changes to my acng.conf file. I've enabled and extended the PfilePattern clause as suggested by GomoX:

PfilePattern = .*(\.d?deb|\.rpm|\.drpm|\.dsc|\.tar(\.gz|\.bz2|\.lzma|\.xz)(\.gpg|\?AuthParam=.*)?|\.diff(\.gz|\.bz2|\.lzma|\.xz)|\.jigdo|\.template|changelog|copyright|\.udeb|\.debdelta|\.diff/.*\.gz|(Devel)?ReleaseAnnouncement(\?.*)?|[a-f0-9]+-(susedata|updateinfo|primary|deltainfo).xml.gz|fonts/(final/)?[a-z]+32.exe(\?download.*)?|/dists/.*/installer-[^/]+/[0-9][^/]+/images/.*)$

and added (this is the important part):

RequestAppendix: Cookie: oraclelicense=a

This will cause acng to send a HTTP cookie with each and every request, but at least makes the oracle binaries pass through and make the installation complete successfully. Tested this with some local Docker images and they download and install Java almost instantaneously!

FWIW: I've created a bug report for acng (#314773, unfortunately not public), so hopefully it will be fixed in an upcoming release...

edit 1: Further testing turned out that it works on Debian Jessie , but not (yet) on Ubuntu Utopic (14:10)...

edit 2: It now also works in Ubuntu Utopic (problem was that I used a Docker image without the ca-certificates package installed).