Skip to content

Instantly share code, notes, and snippets.

@filipelenfers
Last active April 22, 2024 02:02
Show Gist options
  • Save filipelenfers/ef3f593deb0751944bb54b744bcac074 to your computer and use it in GitHub Desktop.
Save filipelenfers/ef3f593deb0751944bb54b744bcac074 to your computer and use it in GitHub Desktop.
Install JDK from tar.gz Ubuntu
#Login as root
sudo su
#create jdk directory
mkdir /opt/jdk
#uncompress, change to your file name
tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk
#check if files are there
#ls /opt/jdk
#update alternatives so the command java point to the new jdk
update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100
#update alternatives so the command javac point to the new jdk
update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100
#check if java command is pointing to " link currently points to /opt/jdk/jdk1.8.0_05/bin/java"
update-alternatives --display java
#check if java command is pointing to " link currently points to /opt/jdk/jdk1.8.0_05/bin/javac"
update-alternatives --display javac
#check if java is running
java -version
@gioipv
Copy link

gioipv commented Mar 17, 2024

  • download open jdk from https://www.openlogic.com/openjdk-downloads?field_java_parent_version_target_id=416&field_operating_system_target_id=426&field_architecture_target_id=391&field_java_package_target_id=396
  • move tar.gz file to /opt/
  • then run
cd /opt/ && \
tar xzf openlogic-openjdk-8u392-b08-linux-x64.tar.gz && \
cd /opt/openlogic-openjdk-8u392-b08-linux-x64/ && \
update-alternatives --install /usr/bin/java java /opt/openlogic-openjdk-8u392-b08-linux-x64/bin/java 2 && \
update-alternatives --install /usr/bin/jar jar /opt/openlogic-openjdk-8u392-b08-linux-x64/bin/jar 2 && \
update-alternatives --install /usr/bin/javac javac /opt/openlogic-openjdk-8u392-b08-linux-x64/bin/javac 2 && \
update-alternatives --set jar /opt/openlogic-openjdk-8u392-b08-linux-x64/bin/jar && \
update-alternatives --set javac /opt/openlogic-openjdk-8u392-b08-linux-x64/bin/javac && \
echo "export JAVA_HOME=/opt/openlogic-openjdk-8u392-b08-linux-x64" >> ~/.bashrc && \
echo "export JRE_HOME=/opt/openlogic-openjdk-8u392-b08-linux-x64/jre" >> ~/.bashrc && \
echo "export PATH=$PATH:/opt/openlogic-openjdk-8u392-b08-linux-x64/bin:/opt/openlogic-openjdk-8u392-b08-linux-x64/jre/bin" >> ~/.bashrc
  • refresh with: source ~/.bashrc
  • test: java -version
openjdk version "1.8.0_392-392"
OpenJDK Runtime Environment (build 1.8.0_392-392-b08)
OpenJDK 64-Bit Server VM (build 25.392-b08, mixed mode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment