You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AWS AMI EC2实例上安装JDK 17?请提供对应的安装命令

Hey there! Installing JDK 17 on an AWS EC2 AMI instance is totally straightforward—let's break it down step by step, since the process varies a bit depending on which Amazon Linux version your AMI is running (most folks use either Amazon Linux 2 or Amazon Linux 2023).

Installing JDK 17 on Amazon Linux 2

  • First, update your system's package index to make sure you're pulling the latest versions:
    sudo yum update -y
    
  • Next, install Amazon Corretto 17—this is AWS's official, open-source JDK optimized for EC2, so it's our top recommendation:
    sudo yum install -y amazon-corretto-17
    
    If you prefer using OpenJDK instead, you can run this command instead:
    sudo yum install -y java-17-openjdk-devel
    
  • Verify the installation worked by checking the Java version:
    java -version
    javac -version
    
    You should see output showing version 17.x.x.
  • (Optional) Set the JAVA_HOME environment variable so your system and applications can find the JDK easily:
    1. Open your bash profile with a text editor (like nano):
      nano ~/.bash_profile
      
    2. Add this line at the end (adjust the path if your JDK is installed elsewhere—you can locate it with find /usr/lib/jvm -name "java-17*"):
      export JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto.x86_64
      
    3. Save and exit (for nano: Ctrl+O, Enter, then Ctrl+X), then reload the profile to apply changes:
      source ~/.bash_profile
      
    4. Confirm it's set correctly:
      echo $JAVA_HOME
      

Installing JDK 17 on Amazon Linux 2023

Amazon Linux 2023 uses dnf instead of yum for package management, so the steps are slightly different:

  • Start by updating your system packages:
    sudo dnf update -y
    
  • Install Amazon Corretto 17 (again, the recommended option):
    sudo dnf install -y amazon-corretto-17
    
    For OpenJDK, use this command instead:
    sudo dnf install -y java-17-openjdk-devel
    
  • Verify the installation:
    java -version
    javac -version
    
  • (Optional) Set JAVA_HOME just like we did for Amazon Linux 2:
    1. Open your bash profile:
      nano ~/.bash_profile
      
    2. Add the export line (check the path with find /usr/lib/jvm -name "java-17*" if needed):
      export JAVA_HOME=/usr/lib/jvm/java-17-amazon-corretto.x86_64
      
    3. Save, exit, and reload the profile:
      source ~/.bash_profile
      
    4. Confirm the variable is set:
      echo $JAVA_HOME
      

That's all! You should have JDK 17 up and running on your EC2 instance in no time.

内容的提问来源于stack exchange,提问作者oOXAam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 12:22:33