×

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

Lambda expressions in Java

A brief introduction to Lambda expression in java In this topic, we will discuss the lambda expression in java. A lambda expression in Java is an enhanced version of an anonymous...

13 minutes read.

Java If Keyword

Definition: The if statement specifies a section of Java code that will run if an if statement's condition is false. The following conditional statements can be used in Java: To provide a block...

3 minutes read.

How to uninstall the Java in Ubuntu

We need java on our computers in our daily lives because there are lots of different applications that are developed using the java environment, so we have to install java...

4 minutes read.

Java Framework List

The framework is the programs which are written in Java. Frameworks in Java are used to create web applications. The code which can reuse can act as a reference for...

6 minutes read.

What’s new in Java 12

On March 19th, 2019, the Java 12th edition was released. After releasing this edition, they have decided to release every new edition every six months. This version is the advanced...

5 minutes read.

Jagged Array in Java

Prerequisite We must first understand what Arrays are and Multi-dimensional Arrays are before we can learn about Jagged arrays. Java Arrays: A collection of data types that are similar is called an...

5 minutes read.

Print Matrix Diagonally in Java

The aim is to print the elements of a matrix of size n*n in some kind of a diagonal pattern. Input : mat[3][3] = {{1, 2, 3},                      {4, 5, 6},                      {7,...

3 minutes read.

Stack in Java

Java provides a number of collection frameworks to store the collection of objects. Among the collection of data structures " Stack " is one of them. Stack is one of...

5 minutes read.

How to take Multiple String Input in Java using Scanner class

Scanner class is a class which takes the multiple input data or the single input data through an objects and methods. The Scanner class will be available in the java.util...

3 minutes read.

Ad Hoc Problem on Arrays in Java

Ad hoc problems are issues that arise unexpectedly and require immediate attention. These problems can range from small and straightforward issues to more complex and time-consuming problems. Examples of ad...

3 minutes read.

Map of Map in Java

The map is now a Java interface for mapping keys to values. It is frequently necessary to use Map of Map (nested Map). Nested Maps are useful in various situations, including...

3 minutes read.

Java vs Dot Net

Java : Java is a pure object oriented language. It was introduced by James Gosling in the year 1995. The first public implementation of java was done by sun micro systems...

3 minutes read.

Java Math atan2() Method

The atan2() method of Math class returns an angle theta from the conversion of rectangular coordinates to polar coordinates. Syntax: public static double atan2(double y, double x) Parameters: The parameter ‘y’ represents the ordinate...

3 minutes read.

Java Boolean getBoolean() Method

The getBoolean() method of Java Boolean class returns true if the specified system property is not null and is equal to the String ‘true’, else the result returned is false. Syntax public...

1 minute read.

Economical number in Java

Economical number is said to be economically efficient if the number of digits after prime factorization of the original number with their powers is less than the number of digits...

3 minutes read.

Java.lang.Exception.NoRunnableMethods

In Programming language, the java lang unexpected no precompiled methods error generally refers to a Junit exception that happens whenever Junit is incapable of locate the precompiled test methods. When...

4 minutes read.

How to Convert int to long in Java

How to Convert int to long in Java When two variables of different types are involved in the single expression, Java compiler uses built-in library function to convert the variable to...

2 minutes read.

Java For Keyword

For as a keyword in java: When we need to run a set of statements repeatedly in Java, we use loops. The Java for loop offers a clear way to express...

4 minutes read.

Structure of Java Program

Java is well-known as an object-oriented, secure, and platform-independent programming language. The Java programming language allows us to construct a wide variety of programs. Therefore, it is essential to fully...

6 minutes read.

Java Trim

Leading and leaving spaces are removed by the built-in Java String trim() method. Space seems to have the Unicode element of "x0040." Java trim() function looks for all of these...

3 minutes read.