Install Oracle JDK 1.8 and Set environment variables in Ubuntu
Step-by-step guide on installing JDK8(Version 1.8)
Some of the environments or projects you work with may specifically need the Java8 (JDK-1.8) for the references. In such instances, the ideal solution is to download the jdk.tar.gz file from the oracle.com and install it from the terminal without depending to apt-get or any other.
The following is the step-by-step guide of how to install and set the environment-variable paths successfully.
Download the JavaSE Development Kit 8 from the given link below.
URL : https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html (Linux x64 : jdk-8u211-linux-x64.tar.gz)
Download the above tar.gz file to “/home/hirosht/Downloads”.
(You might have to login to the Oracle Account to download)
Ps: If any other version of OracleJDK / OpenJDKis installed remove all firstly.
- Open the Terminal (Ctrl + Alt + T)
- Create the jvm folder in usr/lib
$ sudo mkdir /usr/lib/jvm
- Change the working directory
$ cd /usr/lib/jvm
- Extract the downloaded jdk-xuxxx-linux-x64.tar.gz file in the ~/Downloads folder using this command
$ sudo tar -xvzf ~/Downloads/jdk-8u211-linux-x64.tar.gz
- Open the Environment Variable file using Nano-editor or Vi-editor
$ sudo nano /etc/environmentor
$ sudo vi /etc/environment
- Add the following ‘bin-folder-path’ to the existing PATH variable in the opened file (ensure to separate the Path variable by a semicolon [:])
- Add the following JAVA_HOME environment variables at the end of the file.
The modified environment file must looks like following.
8. Save the changes based on the editor opened
— 8.1 If Nano;
— — - Ctrl + O and then Ctrl + X
— 8.2 If Vi;
— — - Press Escape.
— — - Then Shift + Semicolon (:).
— — — Afterwards type (:wq!) and Press Enter
9. Set the Java Location
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_211/bin/java" 0$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_211/bin/javac" 0$ sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_211/bin/java$ sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_211/bin/javac
10. Verify the setup by executing the following commands.
$ update-alternatives --list java
$ update-alternatives --list javac
11. Open the ~/.bashrc with vi-editor to append the following environment variables to the bottom.
$ sudo vi ~/.bashrc
and Press ‘i’ to move into insert in vi-editor. Add the following to the bottom of the doc.
(Ps: I have set the MAVEN_HOME path as well additionally. If its not required please remove those lines before pasting in ‘.bashrc’).
Save the amendment in the doc in vi-editor by following the steps below.
Then Shift + Semicolon (:).
Afterwards type (:wq!)
and Press Enter
12. Verify the Java Version (Restart, if required)
$ java -version
Should display as
13. Verify the JAVA_HOME path.
$ echo $JAVA_HOME
the path should display as follows,
Successfully installed and configured! Feel free to comment below if there is a better approach or if the flow can be improved.