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.
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.
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.
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
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.