Skip to content

Instantly share code, notes, and snippets.

@starlinq
Last active January 27, 2024 19:11
Show Gist options
  • Select an option

  • Save starlinq/9ee5209ceb32b7e05817e714fe530be3 to your computer and use it in GitHub Desktop.

Select an option

Save starlinq/9ee5209ceb32b7e05817e714fe530be3 to your computer and use it in GitHub Desktop.
How to install Java JDK8 in Ubuntu 16.04
  1. Download the latest JDK file

A current link is http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

The latest version is Java SE Development Kit 8u181.

The archive file for Linux x64 is jdk-8u181-linux-x64.tar.gz

Before the file can be downloaded, you must accept the license agreement. The archive binary can be installed by anyone (not only root users), in any location that you can write to. However, only the root user can install the JDK into the system location.

If you download it from web browser, in typical configuration the file will be saved to ~/Downloads directory

  1. Open a terminal using Ctrl+Alt+T key combination

  2. Change a current directory to ~/Downloads

$ cd ~/Downloads
  1. Unpack the tarball
$ tar zxvf jdk-8u181-linux-x64.tar.gz

The Java Development Kit files are installed in a directory called jdk1.8.0_version in the current directory.

You will find a folder with the name as jdk1.8.0_181.

  1. Let's move the directory to default system directory
sudo mv ./jdk1.8.0_181 /usr/lib/jvm

The complete folder “jdk1.8.0_version” will be moved to /usr/lib/jvm.

Step 3: Set environment variables Edit the environment file.

vi /etc/environment

Update the existing PATH variable by adding the below bin folders, separated with a colon :.

/usr/lib/jvm/jdk1.8.0_151/bin:/usr/lib/jvm/jdk1.8.0_151/db/bin:/usr/lib/jvm/jdk1.8.0_151/jre/bin HOME directory paths can be different based on version and update,here the version is 1.8 and the update is 151. Add the below variables at the end of environment file, making changes for your specific version and update.

J2SDKDIR="/usr/lib/jvm/jdk1.8.0_151" J2REDIR="/usr/lib/jvm/jdk1.8.0_151/jre" JAVA_HOME="/usr/lib/jvm/jdk1.8.0_151" DERBY_HOME="/usr/lib/jvm/jdk1.8.0_151/db" The environment file should now be similar to this text:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_151/bin:/usr/lib/jvm/jdk1.8.0_151/db/bin:/usr/lib/jvm/jdk1.8.0_151/jre/bin" J2SDKDIR="/usr/lib/jvm/jdk1.8.0_151" J2REDIR="/usr/lib/jvm/jdk1.8.0_151/jre* JAVA_HOME="/usr/lib/jvm/jdk1.8.0_151" DERBY_HOME="/usr/lib/jvm/jdk1.8.0_151/db" Save changes and close the file.

Step 4: Inform Ubuntu about the installed location Use update-alternatives to inform Ubuntu about the installed java paths.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_151/bin/java" 0

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_151/bin/javac" 0

sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_151/bin/java

sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_151/bin/javac

Step 5: Setup verification Give the location of java and javac as you provided.

update-alternatives --list java

update-alternatives --list javac

Restart the computer or open a new terminal.

Step 6: Verify the Java version

java -version

The output should resemble the following:

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) You should be able to see your installed java version which means you have successfully installed the Oracle JDK.

@Tridip-Barua
Copy link

Finally it works. Thank you!!!

@jardeleko
Copy link

good job, Its a fine docs man

@StefanoWen
Copy link

perfectly worked on ubuntu 16.04!nice job!

@jhutanda
Copy link

jhutanda commented Jan 4, 2021

Thank you. This article is very useful. Finally, I have done my installation.

@gisegalaburri
Copy link

hey man! You're the best!

@VictorAviles
Copy link

Thank you

@ShedrackGodson
Copy link

Worked like a charm!!

@himanshu-anonymous
Copy link

umm Somebody Please Help me

whenever i am trying to execute this command "java -version"
i am getting this error "zsh: exec format error: java"

what should i do??

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