Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alpine Linux - javac not found

I'm trying to build an Alpine Linux image that contains OpenJDK. The Java runtime (java) is installed, but the Java compiler (javac) isn't. I expect the compiler to come with OpenJDK, like how it is when installing via apt or yum.

FROM alpine:latest

RUN apk update
RUN apk add bash openjdk8

RUN java -version
RUN javac --version

When building the Dockerfile, the following error is returned: The command '/bin/sh -c javac -version' returned a non-zero code: 127

How can I have the Java compiler available on Alpine?

like image 453
Jason Avatar asked Jan 21 '19 08:01

Jason


1 Answers

Try this:

FROM alpine:latest
USER root

RUN apk update
RUN apk fetch openjdk8
RUN apk add openjdk8
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
ENV PATH="$JAVA_HOME/bin:${PATH}"

RUN java -version
RUN javac -version
like image 131
taygetos Avatar answered Oct 15 '22 16:10

taygetos