How To Install Java 8 In Ubuntu ( Openjdk 8 )

h4ck3r

Updated on:

Install Java 8 In Ubuntu

Install Java 8 In Ubuntu

Introduction

Java 8, released in 2014, introduced significant improvements and features to the Java programming language. It’s a popular choice for developers and is still widely used in various applications. If you’re an Ubuntu user looking to install Java 8 on your system, you’ve come to the right place. In this comprehensive guide, we’ll walk you through the step-by-step process of installing Java 8 on your Ubuntu machine, ensuring you have all the tools you need for both development and running Java applications.

Why Java 8 ?

Before we follow the installation process, let’s discuss why you might want to install Java 8. Java 8 introduced several key features and enhancements that continue to be valuable for developers to nstall Java 8 In Ubuntu

  1. Lambda Expressions: Java 8 introduced lambda expressions, which simplify code and make it more readable, particularly for functional programming tasks.
  2. Stream API: The Stream API provides a powerful way to work with sequences of data, enabling more concise and expressive code for data manipulation.
  3. Date and Time API: Java 8 introduced a new Date and Time API that addresses the shortcomings of the older Date and Calendar classes, making date and time operations more intuitive.
  4. Default Methods: Default methods allow interfaces to provide method implementations, reducing the need for breaking changes in existing code.

Checking Your Current Java Installation

Before installing Java 8, it’s a good idea to check whether you already have Java installed on your Ubuntu system and which version it is. Open your terminal and run the following command .

java -version

This command will display the version of Java that is currently installed. If you see Java 8 or higher, you may already have a suitable version. If not, it’s time to proceed with the installation to install java 8 in ubuntu.

Installing Java 8 via the Default Ubuntu Repository

Ubuntu’s default repositories include OpenJDK, an open-source implementation of the Java Platform. Java 8 can be installed via these repositories using the following steps:

Step 1

  1. Update Your Package List:
  • Before installing any software, it’s essential to ensure your package list is up to date. Open your terminal and run the following command:
   sudo apt update
  1. Install OpenJDK 8:
  • Once your package list is updated, you can install OpenJDK 8 with the following command:

Download Java 8u191

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3a%2F%2Fwww.oracle.com%2Ftechnetwork%2Fjava%2Fjavase%2Fdownloads%2Fjdk8-downloads-2133151.html; oraclelicense=accept-securebackup-cookie;" "https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.tar.gz"

Download Java 8u131

wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz 

Step 2

  • sudo mkdir /usr/lib/jvm
  • cd ~/usr/lib/jvm
  • sudo tar -xvzf ~/Downloads/jdk-8u191-linux-x64.tar.gz

Configuring Java Environment Variables

To ensure that Java 8 is set up correctly on your Ubuntu system, you may need to configure environment variables. These variables tell your system where to find Java when running Java applications. Here’s how to set up the environment variables:

Step 3

Edit Environment File

  • sudo nano /etc/environment

Add This 3 Lines

  • /usr/lib/jvm/jdk1.8.0_191/bin
  • /usr/lib/jvm/jdk1.8.0_191/db/bin
  • /usr/lib/jvm/jdk1.8.0_191/jre/bin

At The End Of Environment File Paste This

  • J2SDKDIR=”/usr/lib/jvm/jdk1.8.0_191″
  • J2REDIR=”/usr/lib/jvm/jdk1.8.0_191/jre”
  • JAVA_HOME=”/usr/lib/jvm/jdk1.8.0_191″
  • DERBY_HOME=”/usr/lib/jvm/jdk1.8.0_191/db”

Save Using ctrl x y

Step 4

Copy paste all the commands one by one

  • sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.8.0_191/bin/java” 0
  • sudo update-alternatives –install “/usr/bin/javac” “javac” “/usr/lib/jvm/jdk1.8.0_191/bin/javac” 0
  • sudo update-alternatives –set java /usr/lib/jvm/jdk1.8.0_191/bin/java
  • sudo update-alternatives –set javac /usr/lib/jvm/jdk1.8.0_191/bin/javac

Step 5

  • update-alternatives –list java
  • update-alternatives –list javac
  • java -version

Verify the Installation:

  • To verify that Java 8 has been installed successfully, run the following command:
   java -version

Setting Java 8 as the Default Java Version

By default, Ubuntu might have multiple Java versions installed, and it’s essential to set Java 8 as the default version if you intend to use it for development or running Java applications. Use the following steps to set Java 8 as the default:

  1. Update the Alternatives:
  • Run the following command to update the Java alternatives:
   sudo update-alternatives --config java
  1. Select Java 8:
  • You’ll see a list of installed Java versions. Choose the number corresponding to Java 8, and press Enter to set it as the default.
  1. Verify the Default Version:
  • To confirm that Java 8 is now the default version, run:
   java -version

You should see information about Java 8.

Conclusion and Additional Tips

Congratulations! You’ve successfully installed Java 8 on your Ubuntu system. Whether you choose OpenJDK or Oracle JDK, you now have access to the features and capabilities of this powerful Java version. As you embark on your Java development journey, here are

Leave a Comment