- 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
-
Open a terminal using Ctrl+Alt+T key combination
-
Change a current directory to
~/Downloads
$ cd ~/Downloads- Unpack the tarball
$ tar zxvf jdk-8u181-linux-x64.tar.gzThe 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.
- Let's move the directory to default system directory
sudo mv ./jdk1.8.0_181 /usr/lib/jvmThe complete folder “jdk1.8.0_version” will be moved to /usr/lib/jvm.
Step 3: Set environment variables Edit the environment file.
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.
Step 5: Setup verification Give the location of java and javac as you provided.
Restart the computer or open a new terminal.
Step 6: Verify the 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.
Finally it works. Thank you!!!