×

How to Set Java_home in Linux

To set the Java_home in Linux, we must follow several steps to make us understand it easily.

 Java follows the principle called WORA (write once run anywhere). We know that java is platform dependent language.

In this document, we will learn how to set java_home in Linux.

For setting the java_home path, we must install the JDK (java development kit) and JRE (java runtime environment). In the JRE, it contains the JAR (Java Archive files) and libraries to run the java applications, and JRE also contains the JAR files (java archive files) for networking purposes. We need not have to install JRE separately, and if you install JDK, it defaults to install the JRE.

In Linux, the environmental variable holds the different variable data accessible to applications. The data can be about how applications run on the system, different ways of the system behaving etc.

Depending on the system accessibility variable, we can furtherly divide it into two types:

  • Local Environment variable: These variables are used for specific users in the local environmental variable. Only a particular user can access it.
  • Global Environment variable: In the global environment variable, these variables are used for all the users.

For installing java on Linux, we take the support of online websites.

How to Set Java_home in Linux

This is the following website for downloading java on Linux. After getting this interface, scroll down for the Linux file to download, as shown in the figure.

How to Set Java_home in Linux

You can download anyone from the following links as your system preferences.

After installing check, the version of the java using the command as

Javac - -version in the prompt.

After checking the version, you can see the path in the file explorer.

As per my Linux software, the following version is set as the following command.

$PATH
/user/local/bin:/bin:/user/bin:/user/sun/JDK/v1.7.0_16-64bit/bin:

This is the JDK path in the prompt.

Then add the following step .bash_user into the path for accessing the java_home path for a specific user or all the users.

vim ~/bash_user
export JAVA_HOME=/user/sun/JDK/v1.7.0_16-64bit/
export PATH = $JAVA_HOME/bin:$PATH

or

vim /etc/user
export JAVA_HOME=/user/sun/JDK/v1.7.0_16-64bit/
export PATH = $JAVA_HOME/bin:$PATH

This is the set-up for setting the java_home path. After that, you have to open another window prompt by typing the bash through your username. The new variable doesn't add to your present shell and will be opened in the new shell.

We know that we will use the bash command for exiting the path for Linux. If you use the bash shell, it comes with the shell as ~/.bash_username. And if you use the csh shell, it comes up with the path as java_home into the ~/.csh_username. Same as the ksh( k shell), it comes up with the path as java_home into the ~/.ksh_username.

These files are hidden files in the directory in Linux. That's why we use the prefix as the(.) dot symbol in their particular username.

We can also use the “ls - alrt” command for viewing the hidden files.

Let's see an example for creating your reference path:

Sample/usr/username file with the java_home

This is the java_home set up in Linux.

Now, let's see why should we set up the java_home in Linux.

  • Everyone doesn't know about the java_home path. Most people don't set their path for various reasons, and I recommend setting up the java_home path and the class paths for upgrading the system development. Let's see some reasons for setting the java_home path in Linux.
  • After setting the java_home path in Linux, it will be easy to update or upgrade the java version without disturbing the application and configuration files. For that purpose, you have to download the new version of java to your java_home path. It will be the easiest to use the variables.
  • Another benefit is that setting the java_home  environmental variable is shorter than the full path of the JDK installation directory.
  • The java_home environmental variable helps your program achieve platform independency for the scripts that use the java_home. These can be run on Windows, macOS and Linux without specifications and modifications, and you need to set the java_home path in the operating systems.
  • Java_home can access all all-standard users.

Related Topics

Getting the Day from the Date in Java?

To extract the day's name from the date, we will write Java application. When dealing the date and time in Java, the following classes are used. Class for Calendars: This class is...

6 minutes read.

Java Buffer Reader

When a variable cannot change its value during run time is called a Static way of programming. In this programming, a variable is directly assigned to a value. Program: Import java.io.*; class  A {  ...

4 minutes read.

List of Constants in Java

In this tutorial, we are going to deal with constants available in Java.Every programming language has its constants. Similarly, Javaalso has got constants of its own. In this tutorial, we will...

6 minutes read.

XOR of Array Elements Except Itself in Java

A lot of the biggest IT organisations, including The Google, Amazon, TCS, and The Accenture, etc., question about this issue in their interview processes. By addressing the issue, one hopes to assess...

5 minutes read.

Java Class Methods

Methods called on a class rather than a specific object instance are known as class methods. The static modifier guarantees uniform implementation across all instances of the class. Syntax public class NameOfClass...

3 minutes read.

Java Math log10() Method

The log10() method of Math class returns the base 10 logarithmic value for the specified double argument. Syntax: public static double log10(double a) Parameters: The parameter ‘a’ represents a double value. Return Value: The log10() method...

2 minutes read.

Transient variable in Java

In this article, you will be acknowledged about transient variable along with its functions. We would conclude by understanding an example program about it. Transient variable By introducing the transitory keyword, we...

3 minutes read.

Deadlock in Java

Deadlock is when two or more processes wait for the state to do their tasks, but none of them can do so. It is a very common problem that one...

6 minutes read.

Java Location

PATH is an environmental variable that the system software now uses to find executable files (.exe) or Java binaries ( java or javac command). Once chosen, a route cannot be...

3 minutes read.

Java 8 Features

Java 8 Features: After the great success of Java 7, many developers were waiting for the next version of one of the best languages in the tech world. Moreover, on...

6 minutes read.

Multithreading Program in Java

Multithreading Program in Java: Before discussing multithreading, it is important to discuss threads. Threads are the most fundamental part of a process. A process can have one or more threads....

4 minutes read.

ArrayDeque in Java

ArrayDeque The ArrayDeque is one of the essential concepts in java to implement the deque interface. It will allow us to apply a resizable array to implement the Deque interface. This...

8 minutes read.

String Handling Method in Java

What is a String? Strings are a bundle of different characters that are normally used in Java programming language. Strings are regarded as objects in the Java programming language. “String” is a...

4 minutes read.

String Programs in Java

String Programs in Java: In Java, a String is an immutable object that represents a sequence of characters. For example, “Tutorial” is a string that consists of 8 characters: ‘T’,...

10 minutes read.

Java gc()

Garbage collection Java language provides different ways to perform the task of memory management. In Java, objects are declared and assigned references. Once lifeof an object is completed it is dereferenced...

4 minutes read.

Java Binary Operators

In this article, we are going to discuss about the binary operators in Java and their operations. Also, an example program will be discussed along with the operations. These are...

6 minutes read.

Narcissistic Number in Java

A Narcissistic number is made up of digits that have been added together and raised to powers equal to the number of digits in the original number. In those other...

3 minutes read.

Null Pointer Exception in Java

It is a runtime error exception. The null value is allocated to the object reference in this exception. We will explicitly throw this null pointer exception when the program wants...

3 minutes read.

Get year from date in Java

The getYear() method of the Java date class returns a number calculated by deducting 1900 from the year that contains or starts with the instant in time represented by this...

4 minutes read.

Java Math toRadians() Method

The toRadians() method of Java Math class converts an angle measured in degrees to an approximately equivalent angle measured in radian. Syntax: public static double toRadians (double angdeg) Parameters The parameter ‘angdeg’ represents an...

2 minutes read.