DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How to Migrate from Java 8 to Java 17+ Using Amazon Q Developer
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Video Generation With Java: Leverage Nova and Amazon Bedrock
  • Leverage Amazon BedRock Chat Model With Java and Spring AI

Trending

  • Part 4: Multi-Agent Orchestration — Pairing Goose With Quarkus Flow State Machines
  • The SDLC After AI
  • MQTT, Kafka, NATS, or Zenoh? Choosing Edge-to-Cloud Messaging by Traffic Pattern
  • Applying Microservices Lessons to Multi-Agent AI Systems

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Tools
  4. Installing Java 8 on AWS EC2 Amazon Linux Instance

Installing Java 8 on AWS EC2 Amazon Linux Instance

Take a quick look at this brief tutorial showing you how to install Java 8 in an Amazon EC2 instance.

By 
Ajay Sodhi
·
Jan. 30, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
186.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Today we are going to install Java 8 (JDK 8, I must say from the developer's perspective) in an Amazon EC2 instance which is having an Amazon Linux version installed on it. In a nutshell, we can say that Amazon Linux can be considered equivalent to CentOS 6.

I am not going to waste your time and will instead jump directly towards the commands that you have to execute to install JDK 8 on your new instance. Before we start, please ensure you have the administrative privileges. OK. So, you have to execute the following commands as mentioned below.

Installing Java 8


$ cd /opt

$ sudo wget --no-cookies --no-check-certificate --header "Cookie: %3A%2F%2Fwww.oracle.com%2F; -securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz

$ sudo tar xzf jdk-8u151-linux-x64.tar.gz

$ cd jdk1.8.0_151/

$ sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_151/bin/java 2

$ sudo alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------

*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /opt/jdk1.8.0_151/bin/java

Enter to keep the current selection[+], or type selection number: 2 


(If you are getting some other options as well, choose the one with "/opt/jdk1.8.0_151/bin/java")

Now let's set alternatives, so that once Java is called, it points to the correct JDK version through following commands:

$ sudo alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_151/bin/jar 2

$ sudoalternatives --set jar /opt/jdk1.8.0_151/bin/jar

$ sudo alternatives --set javac /opt/jdk1.8.0_151/bin/javac

Check Java Version 

$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Setting Environment Variables.

We can set the environment variables either user based or globally. With following approach, we are setting the environment variable globally, so that any user on this machine can access it. 

# vim /etc/profile

export JAVA_HOME=/opt/jdk1.8.0_151
export JRE_HOME=/opt/jdk1.8.0_151/jre
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

Esc + :wq! (To save file)


Congratulations!! You did it!


AWS Java (programming language) Linux (operating system)

Opinions expressed by DZone contributors are their own.

Related

  • How to Migrate from Java 8 to Java 17+ Using Amazon Q Developer
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • Video Generation With Java: Leverage Nova and Amazon Bedrock
  • Leverage Amazon BedRock Chat Model With Java and Spring AI

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook