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
Over 2 million developers have joined DZone.
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

  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • No More Cheap Claude: 4 First Principles of Token Economics in 2026
  • AWS Kiro: The Agentic IDE That Makes Specs the Unit of Work
  • How AI Is Rewriting Full-Stack Java Systems: Practical Patterns with Spring Boot, Kafka and WebSockets
  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 user avatar
Ajay Sodhi
·
Jan. 30, 18 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
186.1K Views

Join the DZone community and get the full member experience.

Join For Free

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

The likes didn't load as expected. Please refresh the page and try again.

  • 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