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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  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.

Ajay Sodhi user avatar by
Ajay Sodhi
·
Jan. 30, 18 · Tutorial
Like (5)
Save
Tweet
Share
181.80K 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.

Popular on DZone

  • AIOps Being Powered by Robotic Data Automation
  • Do Not Forget About Testing!
  • How To Convert HTML to PNG in Java
  • Mr. Over, the Engineer [Comic]

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: