Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install JDK 8 update 172 in dockerfile with ubuntu image

I am used to download java in my dockerfile like this :

# Install Java
ENV JAVA_VERSION_MAJOR 8
ENV JAVA_VERSION_MINOR 162
ENV JAVA_VERSION_BUILD 12
ENV JAVA_DOWNLOAD_HASH 0da788060d494f5095bf8624735fa2f1
RUN mkdir -p /usr/lib/jvm \
    && cd /usr/lib/jvm \
    && wget -nv --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-b${JAVA_VERSION_BUILD}/${JAVA_DOWNLOAD_HASH}/jdk-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz \
    && tar xf jdk-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz \
    && rm jdk-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz \
    && update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.${JAVA_VERSION_MAJOR}.0_${JAVA_VERSION_MINOR}/bin/java" 1
ENV JAVA_HOME /usr/lib/jvm/jdk1.${JAVA_VERSION_MAJOR}.0_${JAVA_VERSION_MINOR}

Apparently, oracle has released new update 8u172 and download within dockerfile is failing with ERROR 404: Not Found.

My question is , how do I find out JAVA_DOWNLOAD_HASH variable ?

Rest of variable values are clear to me :

JAVA_VERSION_MAJOR 8
JAVA_VERSION_MINOR 172
JAVA_VERSION_BUILD 11

Please note that my base docker image is : ubuntu:16.04

My installation of java within ubuntu is inspired from here

like image 473
Utsav Chokshi Avatar asked Apr 19 '18 06:04

Utsav Chokshi


People also ask

How do I update Java on Ubuntu?

Conclusion. Open the terminal and type “sudo apt install default-jre” to install JRE, and type “sudo apt install default-jdk” to install JDK on ubuntu 22.04. To check or verify the java version type “java -version” on the terminal of Ubuntu 22.04.


1 Answers

I think oracle has fixed broken web8upd.

So now dockerfile specified on github works perfectly !

Just copy-pasting same dockerfile with some modifications :

FROM ubuntu:16.04

# To solve add-apt-repository : command not found
RUN apt-get -y install software-properties-common

# Install Java
RUN \
  echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  add-apt-repository -y ppa:webupd8team/java && \
  apt-get update && \
  apt-get install -y oracle-java8-installer --allow-unauthenticated && \
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /var/cache/oracle-jdk8-installer


# Define commonly used JAVA_HOME variable
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

Please note : rm -rf /var/lib/apt/lists/* will remove all lists fetched by apt-get update.

So if you want to install more things after installing Java, remove rm -rf /var/lib/apt/lists/* otherwise you have to run apt-get update again.

like image 94
Utsav Chokshi Avatar answered Oct 05 '22 12:10

Utsav Chokshi