Skip to content
Advertisement

How do I install JDK 17 on my AWS AMI Ec2 instance? [closed]

I need to install JDK 17 on my AWS EC2 AMI instance.

Is there any command? Any answers would be appreciated!

Advertisement

Answer

Install with package managers:

deb-based distros (such as Debian or Ubuntu)

# Download deb package from https://www.oracle.com/java/technologies/downloads/
# And then
sudo dpkg -i jdk-17_linux-x64_bin.deb

rpm-based distros (such as RHEL or CentOS)

# Download rpm package from https://www.oracle.com/java/technologies/downloads/
# And then
sudo rpm -i jdk-17_linux-x64_bin.rpm 

Any distro without or with differrent package manager

Download x64 Compressed tar.gz Archive from https://www.oracle.com/java/technologies/downloads/

Create jvm directory

sudo mkdir -p /usr/lib/jvm

Change to the directory.

cd /usr/lib/jvm

Extract jdk-17_linux-x64_bin.tar.gz to that directory.

~/Downloads/ – is a directory where archive is saved. If your downloaded file is in any other location, change the command according to your path.

sudo tar -xvzf ~/Downloads/jdk-17_linux-x64_bin.tar.gz

Enter the following command to open the environment variables file.

sudo ${EDITOR} /etc/environment

Edit your ${PATH}

# Add this to the $PATH variable
/usr/lib/jvm/jdk-17/bin

Add the following environment variables at the end of the file.

JAVA_HOME="/usr/lib/jvm/jdk-17"

Inform the system about the Java’s location.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-17/bin/java" 0
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-17/bin/javac" 0
sudo update-alternatives --set java /usr/lib/jvm/jdk-17/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/jdk-17/bin/javac

To check version:

java -version
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement