Skip to content

Instantly share code, notes, and snippets.

@filipelenfers
Last active April 6, 2024 12:31
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
@ynsmtkl
Copy link

ynsmtkl commented May 29, 2018

thanks, steps more clear than oracle website 👍

@maxzap
Copy link

maxzap commented Jun 22, 2018

thanks!

@dsatul
Copy link

dsatul commented Jun 26, 2018

Thanks

@Fabio-Drunn
Copy link

valeu!!

@elyess78
Copy link

thanks,very useful!!

@fahamjv
Copy link

fahamjv commented Aug 18, 2018

root@GHOST:/home/batman/Downloads# java -version
bash: /usr/bin/java: cannot execute binary file: Exec format error
root@GHOST:/home/batman/Downloads#

what should i do ?

@jsalvad0r
Copy link

thanks buddy

@abdhx
Copy link

abdhx commented Dec 18, 2018

You saved my life! thanks

@peterwilli
Copy link

Also works on Debian 9.6 :)

@ant-rod-silva
Copy link

Thanks!!! Working on Ubuntu 12

@claudiopmaia
Copy link

thanks

@LongClipeus
Copy link

thanks

@byhankim
Copy link

byhankim commented May 4, 2019

You saved my day. Thanks!

@derrickpeavy
Copy link

derrickpeavy commented May 16, 2019

Awesome! Thank you!

@llinuxde
Copy link

llinuxde commented Jun 26, 2019

thanks! works well on Debain 9

@mdradityatama
Copy link

thanks

@shoniisra
Copy link

It could be the last step if your java version doesn't change (show and choose from list alternatives)
sudo update-alternatives --config java

@anjali965
Copy link

Thanks ,It worked :)

@amieldanao
Copy link

Thank you

It could be the last step if your java version doesn't change (show and choose from list alternatives)
sudo update-alternatives --config java

Thank you

@DevStark22
Copy link

Thanks men !

@henriquecalasans
Copy link

Thanks!! man

Copy link

ghost commented Aug 25, 2020

Thanks man. very helpful

@romec512
Copy link

👍

@Humeid-Ussene-Jocordasse

Voce merece um abraço irmão

@sauron34
Copy link

Thank you very much!

@Lubrum
Copy link

Lubrum commented Sep 20, 2021

Thanks :D (from Dom Pedrito - RS - Brazil)

@PepeDahPhrog
Copy link

Thank you very much, you need a monument !

@JeanPascalTrinh
Copy link

MERCI JE T'AIME

@kfreemantle
Copy link

Thank you! I'm super new to the command line and this was very easy to follow.

@julianapetrelli
Copy link

Thanks :D
(from Araras - SP - Brazil)

@giuseppericci
Copy link

Hi the command java -version it gives java command not found.
Please can help me? I'm on Debian VM.
Thanks.

@filipelenfers
Copy link
Author

Hi the command java -version it gives java command not found.
Please can help me? I'm on Debian VM.
Thanks.

Hi @giuseppericci ! Probably something went wrong and you don’t have Java on the /usr/bin/java location. Check if any of the commands failed and try them again.

Also, if you don’t need to install java from a tar.gz file, you can always run an “sudo apt install default-jdk” to get the last OpenJDK provided the Debian.
This link may help: https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-on-debian-11

@goutam181
Copy link

Thanks...it is worked

@dgonzalez211
Copy link

It could be the last step if your java version doesn't change (show and choose from list alternatives) sudo update-alternatives --config java

Thank you so much

@kotnibf
Copy link

kotnibf commented Jun 9, 2023

Thank you

@guillemc23
Copy link

been searching hours for this! thank you buddy

@Dr-Darvin
Copy link

If you install it on the latest Ubuntu version, it may give an error,
This link may help: https://askubuntu.com/questions/634024/bash-usr-bin-java-no-such-file-or-directory

@WolfBoy55014
Copy link

Worked for me on Ubuntu 22.04!
Thank you so much :D

@samhuawey
Copy link

Does not work for Oracle Java since they have --- for other users in tgz permissions. One needs to chmod o+x before users are able to start java.

@strouja
Copy link

strouja commented Feb 28, 2024

Thanks, this is what I ended up doing last night, i did as the root user and you can copy and paste this block

sudo apt install wget -y # in case you do not have wget
wget https://github.com/ibmruntimes/semeru11-binaries/releases/download/jdk-11.0.22%2B7_openj9-0.43.0/ibm-semeru-open-jdk_x64_linux_11.0.22_7_openj9-0.43.0.tar.gz
tar -xzvf ibm-semeru-open-jdk_x64_linux_11.0.22_7_openj9-0.43.0.tar.gz -C /usr/local/bin
mv /usr/local/bin/jdk-11.0.22+7 /usr/local/bin/java
sudo cat >> /etc/environment << EOF
PATH="$PATH:/usr/local/bin/java/bin"
EOF
source /etc/environment
java -version

This will show something like

openjdk version "11.0.22" 2024-01-16
IBM Semeru Runtime Open Edition 11.0.22.0 (build 11.0.22+7)
Eclipse OpenJ9 VM 11.0.22.0 (build openj9-0.43.0, JRE 11 Linux amd64-64-Bit Compressed References 20240131_966 (JIT enabled, AOT enabled)
OpenJ9   - 2c3d78b48
OMR      - ea8124dbc
JCL      - 7876cac747 based on jdk-11.0.22+7)

The reason why I did this command mv /usr/local/bin/jdk-11.0.22+7 /usr/local/bin/java so we do not have the java version number hard coded in the directory. this way later on if you update the java by laying down new files in /usr/local/bin/java you do not have to update the path again that I set in /etc/environment

@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