Schelldorfer
Schelldorfer

Reputation: 311

How to install different Java OpenJDK version on AWS CodeBuild standard image

AWS CodeBuild docker images for Ubuntu and Amazon Linux 2 platform support Java LTS versions (currently Java 8 and Java 11).

see https://docs.aws.amazon.com/codebuild/latest/userguide/available-runtimes.html

How can I install a different OpenJDK version (e.g. latest OpenJDK)?

Upvotes: 2

Views: 4137

Answers (2)

There is another way if you follow this link

installing_java_17_amazon_corretto

I just tried it on one of my projects, and it works.

Upvotes: 0

Schelldorfer
Schelldorfer

Reputation: 311

To install latest OpenJDK on aws/codebuild/amazonlinux2-x86_64-standard:3.0 image, use the following buildspec.yml:

version: 0.2

phases:
  install:
    commands:
      - uname -a
      - yum update -y
      - echo list available openjdk packages
      - yum list *openjdk*
      - echo install openjdk packages
      - yum install -y java-latest-openjdk-devel java-latest-openjdk-jmods
      - echo show default java version
      - echo $JAVA_HOME
      - java -version
      - cd /usr/lib/jvm
      - ls
      - export JAVA_HOME=/usr/lib/jvm/java-openjdk
      - cd $JAVA_HOME/bin
      - java -version
      - echo configure java command
      - alternatives --install /usr/bin/java java /usr/lib/jvm/java-openjdk/bin/java 20000
      - alternatives --set java /usr/lib/jvm/java-openjdk/bin/java
      - alternatives --display java
      - echo configure javac command
      - alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-openjdk/bin/javac 20000
      - alternatives --set javac /usr/lib/jvm/java-openjdk/bin/javac
      - alternatives --display javac
      - echo show updated java version
      - java -version
      - cd $CODEBUILD_SRC_DIR

Upvotes: 2

Related Questions