DEV Community

bhuvana-guna
bhuvana-guna

Posted on

2

How I installed Oracle JDK 8 in Ubuntu 18.04.1 LTS


Today I tried installing JAVA in my new Ubuntu system and followed the conventional method of downloading it through ppa:webupd8team/java oracle-java8-installer following this link.

Even though I successfully installed the default JDK and JRE, I was not able to install Oracle JDK which was needed for Android Studio.

After some research, I found out through this link that as of April 16, 2019, you won't be able to download Oracle JDK without signing in to an Oracle account. This stackoverflow answer too helped me.

With all these help these are steps I followed to install Oracle JDK.

  • Download the latest JAVA 8 SE development kit from here after creating or signing in to the Oracle account.

  • Open your terminal and type

    $mkdir /opt/jdk
    
  • Untar Java in your new folder

    $tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk
    
  • I installed using these commands (don't forget to replace with the one you installed.)

    $update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_<YourVersion>/bin/java 100
    $update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_<YourVersion>/bin/javac 100
    
  • To set oracle JDK as the default JVM, run

    $sudo update-alternatives --config java
    

    and select the Oracle JDK that you installed. And also do the same for java compiler,

     $sudo update-alternatives --config javac
    
  • Set the JAVA_HOME Environment Variable using the following commands.

      $sudo nano /etc/environment
    

    add this line

    JAVA_HOME="/opt/jdk/jdk1.8.0_<YourVersion>/bin/java" 
    

    and save the file, exit. Now reload and check using,

    $source /etc/environment
    
    $echo $JAVA_HOME
    
  • Check if the java version is right

    $java -version
    

Hope this helped you.

AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay