Tuesday, 15 October 2024

JDK 11 Installation on Linux OS and Amazon EC2 Explained | Running JDK 11 on AWS EC2 or Linux OS

Join the Ram N Java Community! 🚀

Subscribe to get the latest Java, AWS, and Cloud tutorials delivered straight to you!

SUBSCRIBE ON YOUTUBE

Overview

Installing Java Development Kit (JDK) 11 on an Amazon EC2 instance or any Linux-based server is a fundamental step for Java developers. This guide will walk you through the process, from updating your system to verifying your installation.

Step 1: Update Your Linux System

Before installing any new software, it is a best practice to ensure your existing packages are up to date. This minimizes compatibility issues.

sudo yum update
sudo yum upgrade

Step 2: Download the JDK 11 Archive

Visit the Oracle JDK 11 download page and locate the Linux 64 compressed archive (ending in .tar.gz). You can download it directly to your server using wget or download it locally and transfer it via WinSCP.

  • Using WinSCP: Log in to your EC2 instance and drag the downloaded .tar.gz file into your home directory (e.g., /home/ec2-user).

Step 3: Extract JDK to /opt Directory

The /opt directory is a standard location for optional software packages. Extract your archive there:

sudo tar -xvf jdk-11.0.x_linux-x64_bin.tar.gz -C /opt

Verify the extraction by listing the contents of /opt:

ls /opt

Step 4: Set Environment Variables

To make Java available system-wide, you must configure the JAVA_HOME and PATH variables. Open the global profile file:

sudo nano /etc/profile

Scroll to the bottom and add these lines (ensure the path matches your extracted version):

export JAVA_HOME=/opt/jdk-11.0.23
export PATH=$JAVA_HOME/bin:$PATH

Save (Ctrl+X, then Y, then Enter) and refresh your session:

source /etc/profile

Step 5: Verify Installation

Confirm that JDK 11 is correctly installed and active:

java -version
javac -version

You should see output indicating "java version 11.x.x".

Conclusion

Congratulations! You have successfully configured JDK 11 on your Amazon EC2 instance. You are now ready to run Java applications or set up a build environment for your projects.

No comments:

Post a Comment

Tutorials