title: Failed to install Jenkins with JDK 11 on Amazon EC2 Linux 2 AMI with Packer
body: <p>I try to install <strong>EC2</strong> instance, with pre-installed Jenkins, using the following <strong>Packer</strong> configuration:</p>
  <p>The most important part here is <strong>setup.sh</strong> script, which installs <strong>Jenkins</strong> and <strong>Java</strong>:</p>
  <pre><code>#!/bin/bash
  
  echo &quot;Installing Amazon Linux extras&quot;
  amazon-linux-extras install epel -y
  
  echo &quot;Install Jenkins stable release&quot;
  yum remove -y java
  yum install -y java-11-openjdk-devel
  wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
  rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
  yum install -y jenkins
  chkconfig jenkins on
  
  echo &quot;Install git&quot;
  yum install -y git
  
  echo &quot;Setup SSH key&quot;
  mkdir /var/lib/jenkins/.ssh
  touch /var/lib/jenkins/.ssh/known_hosts
  chown -R jenkins:jenkins /var/lib/jenkins/.ssh
  chmod 700 /var/lib/jenkins/.ssh
  mv /tmp/id_rsa /var/lib/jenkins/.ssh/id_rsa
  chmod 600 /var/lib/jenkins/.ssh/id_rsa
  chown -R jenkins:jenkins /var/lib/jenkins/.ssh/id_rsa
  
  echo &quot;Configure Jenkins&quot;
  mkdir -p /var/lib/jenkins/init.groovy.d
  mv /tmp/scripts/*.groovy /var/lib/jenkins/init.groovy.d/
  chown -R jenkins:jenkins /var/lib/jenkins/init.groovy.d
  mv /tmp/config/jenkins /etc/sysconfig/jenkins
  chmod +x /tmp/config/install-plugins.sh
  bash /tmp/config/install-plugins.sh
  service jenkins start
  </code></pre>
  <p><strong>See all other configuration files by this link:</strong></p>
  <p><a href="https://github.com/mlabouardy/pipeline-as-code-with-jenkins/tree/master/chapter4/distributed/master" rel="nofollow noreferrer">https://github.com/mlabouardy/pipeline-as-code-with-jenkins/tree/master/chapter4/distributed/master</a></p>
  <p>When I run:</p>
  <pre><code>packer build template.json
  </code></pre>
  <p>I get the following exception:</p>
  <pre><code>==&gt; amazon-ebs: Job for jenkins.service failed because the control process exited with error code. See &quot;systemctl status jenkins.service&quot; and &quot;journalctl -xe&quot; for details.
  </code></pre>
  <p><strong>Everything works perfectly, If I use:</strong></p>
  <pre><code>yum install -y java-1.8.0-openjdk
  </code></pre>
  <p><strong>instead of:</strong></p>
  <pre><code>yum install -y java-11-openjdk-devel
  </code></pre>
  <p>I'm able to start Jenkins, but I see the following warning:</p>
  <p><code>Using Java 8 with the latest Jenkins is not recommended</code></p>
  <p>Does anyone know how to make this configuration work with Java 11 ?</p>
  <p><strong>P.S.
  As a Source Amazon Machine Image for Packer I use:</strong></p>
  <pre><code>Amazon Linux 2 AMI (HVM), SSD Volume Type - ami-02e136e904f3da870 (64-bit x86) / ami-0e341fcaad89c3650 (64-bit Arm)
  </code></pre>
  <p>It is available in the &quot;<strong>us-east-1</strong>&quot; region (&quot;<strong>source_ami</strong>&quot; : &quot;<strong>ami-02e136e904f3da870</strong>&quot; - the exact id of <strong>Amazon Linux 2 AMI</strong> depends on the region)</p>
  <p>Here is the Packer <strong>template.json</strong>, which is used for baking <strong>Jenkins Image</strong> from the <strong>Source Image</strong>:</p>
  <pre><code>{
      &quot;variables&quot; : {
          &quot;region&quot; : &quot;us-east-1&quot;,
          &quot;aws_profile&quot;: &quot;ops-account&quot;,
          &quot;source_ami&quot; : &quot;ami-02e136e904f3da870&quot;,
          &quot;instance_type&quot;: &quot;t2.micro&quot;,
          &quot;ssh_key&quot;: &quot;./jenkins_ssh&quot;
      },
      &quot;builders&quot; : [
          {
              &quot;type&quot; : &quot;amazon-ebs&quot;,
              &quot;profile&quot; : &quot;{{user `aws_profile`}}&quot;,
              &quot;region&quot; : &quot;{{user `region`}}&quot;,
              &quot;instance_type&quot; : &quot;{{user `instance_type`}}&quot;,
              &quot;source_ami&quot; : &quot;{{user `source_ami`}}&quot;,
              &quot;ssh_username&quot; : &quot;ec2-user&quot;,
              &quot;ami_name&quot; : &quot;jenkins-master-2.204.1&quot;,
              &quot;ami_description&quot; : &quot;Amazon Linux Image with Jenkins Server&quot;,
              &quot;run_tags&quot; : {
                  &quot;Name&quot; : &quot;packer-builder&quot;
              }
          }
      ],
      &quot;provisioners&quot; : [
          {
              &quot;type&quot; : &quot;file&quot;,
              &quot;source&quot; : &quot;./scripts&quot;,
              &quot;destination&quot; : &quot;/tmp/&quot;
          },
          {
              &quot;type&quot; : &quot;file&quot;,
              &quot;source&quot; : &quot;./config&quot;,
              &quot;destination&quot; : &quot;/tmp/&quot;
          },
          {
              &quot;type&quot; : &quot;file&quot;,
              &quot;source&quot; : &quot;{{user `ssh_key`}}&quot;,
              &quot;destination&quot; : &quot;/tmp/id_rsa&quot;
          },
          {
              &quot;type&quot; : &quot;shell&quot;,
              &quot;script&quot; : &quot;./setup.sh&quot;,
              &quot;execute_command&quot; : &quot;sudo -E -S sh '{{ .Path }}'&quot;
          }
      ]
  }
  </code></pre>