Installing Java 8 and Setting environment variables

12,793

Solution 1

I have been using that webupd8 PPA for a long time, and it has always worked fine for me.

Look at this similar question/answer

For your general question about PPAs... Using PPAs is a fact of life for many 3rd party software apps in Ubuntu. There is nothing inheritely wrong/bad with it at all. Of course, it's always best to stick with the supported archives, but sometimes you can't, and I find PPAs are much saner than a bunch of randomly downloaded software.

Especially for a recent switcher to Ubuntu, I think the experience is much nicer with PPAs.

Solution 2

Actually all these PPAs are from third parties. Oracle does not provide any PPA, and the manual way of installing Oracle JDK 8 is explained in step by step manner in this article : Install Latest Oracle JDK in Ubuntu

Step 1: Download the latest JDK(jdk-Xuxx-linux-xXX.tar.gz) from this official link.

Step 2: Open the terminal (Ctrl + Alt + T) and enter the following command.

sudo mkdir /usr/lib/jvm

Step 3: Enter the following command to change the directory.

cd /usr/lib/jvm

Step 4: Extract the jdk-Xuxx-linux-xXX.tar.gz file in that directory using this command.

sudo tar -xvzf ~/Downloads/jdk-8u45-linux-x64.tar.gz

Step 5: Enter the following command to open the environment variables file.

sudo -H gedit /etc/environment

Step 6: In the opened file, add the following bin folders to the existing PATH variable.

/usr/lib/jvm/jdk1.8.0_45/bin
/usr/lib/jvm/jdk1.8.0_45/db/bin
/usr/lib/jvm/jdk1.8.0_45/jre/bin

The PATH variables have to be separated by colon. Notice that the installed JDK version is 1.8 update 45. Depending on your JDK version, the paths can be different. Add the following environment variables at the end of the file.

J2SDKDIR="/usr/lib/jvm/jdk1.8.0_45"
J2REDIR="/usr/lib/jvm/jdk1.8.0_45/jre"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_45"
DERBY_HOME="/usr/lib/jvm/jdk1.8.0_45/db"

The environment file before the modification:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

The environment file after the modification:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_45/bin:/usr/lib/jvm/jdk1.8.0_45/db/bin:/usr/lib/jvm/jdk1.8.0_45/jre/bin"
J2SDKDIR="/usr/lib/jvm/jdk1.8.0_45"
J2REDIR="/usr/lib/jvm/jdk1.8.0_45/jre"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_45"
DERBY_HOME="/usr/lib/jvm/jdk1.8.0_45/db"
Share:
12,793

Related videos on Youtube

PeakGen
Author by

PeakGen

CTO

Updated on September 18, 2022

Comments

  • PeakGen
    PeakGen over 1 year

    I just completly shifted to Ubuntu from Windows 7. I am a java developer and now I need to install Java 8 JDK and JRE. I installed 64 bit ubuntu 14.04.02 and it seems like there are lot of ways to install the Oracle Java JDK, but I am not understanding any of it properly (mostly because the tutorials are outdated!).

    Now, the easiest way I found is in here -http://tecadmin.net/install-oracle-java-8-jdk-8-ubuntu-via-ppa/

    But I am not sure whether this is a good idea to install via a PPA because it is coming from a third party source.

    I didn't monitor any step by step guide on askubuntu about installing the Java JDK 8. Can someone help me with that please? Just installing is not enough, setting up the environment variables also mandatory.

    Anyway, if the PPA is the recommended best way, please let me know that too.