简体   繁体   中英

AWS - How to install java11 on an EC2 Linux machine?

I tried this

Downloading Java JDK on Linux via wget is shown license page instead

but I keep getting a 404 error.

This command "sudo amazon-linux-extras install java-openjdk11" just states that amazon-linux-extras doesnt exist.

Another option might be running the following commands:

In order to install java 11:

sudo amazon-linux-extras install java-openjdk11

For java 8 you can try:

sudo yum install java-1.8.0-openjdk

Finally, if you want to switch between java versions run:

sudo alternatives --config java

Sharing my simple working approach

Downloading the JDK

curl -LO https://corretto.aws/downloads/latest/amazon-corretto-11-x64-linux-jdk.tar.gz

Extracting the JDK to /usr/java/

sudo tar -xvzf amazon-corretto-11-x64-linux-jdk.tar.gz -C /usr/java/

Run the below single line command to change the soft link for java files in (/usr/bin) directory

for i in /usr/java/amazon-corretto-11.0.12.7.1-linux-x64/bin/java /usr/java/amazon-corretto-11.0.12.7.1-linux-x64/bin/javac /usr/java/amazon-corretto-11.0.12.7.1-linux-x64/bin/jfr; do f=$(basename $i); echo $f; sudo alternatives --install /usr/bin/$f $f $ i 20000 ; sudo update-alternatives --config $f ; done

after the above command execution, there will be a command prompt that will ask you to choose the selection number which represents the file residing path and we should choose the number which refers to path /usr/java/amazon-corretto-11.0.12.7.1-linux-x64/bin/

That's it execute java -version , you can see the java version as

openjdk version "11.0.12" 2021-07-20 LTS
OpenJDK Runtime Environment Corretto-11.0.12.7.1 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.12.7.1 (build 11.0.12+7-LTS, mixed mode)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM