How To Set JAVA_HOME Environment Variable For All Users In Linux?

How To Set JAVA_HOME Environment Variable For All Users In Linux?

   

This post was last updated on May 9th, 2020 at 03:46 pm

An environment variable is a variable whose value is set outside the program, Typically through a functionality built into the operating system. Generally, environment variables contains information such as drive, path, or filename. It can change the behavior of a program in the system. JAVA_HOME is an environment variable that points to the directory where the Java runtime environment (JRE) is installed on your computer. In this article, we will show you how to set the JAVA_HOME variable correctly for all users in a Linux system.

How to install java?

First of all, you need to install java in your system, if you install an application that requires the java runtime environment. Use the following command to install it in your system.

First, update the package index of apt with-

sudo apt-get update

And then execute –

sudo apt-get install default-jdk

You can verify the installation with –

java --version

For a detailed Java installation guide, you can follow this article.

Find the location where java is installed

Now the application that requires java needs to know the location where java is installed. This path is commonly referred to as “JAVA_HOME”. The easiest way to check that location is by running this command –

sudo update-java-alternatives -l

This will display the following output in the terminal –

Copy the string that is highlighted in red.

Set JAVA_HOME environment variable

The /etc/profile is a file that contains Linux system-wide environment and startup programs. It is used to set the PATH variable, user limits, and other settings for the users. We will edit this file to set the JAVA_HOME variable. Now follow the below steps –

1. Open /etc/profile with a text editor –

sudo nano /etc/profile

2. Copy and paste the following at the end of this file –

export JAVA_HOME="path of java"
export PATH=$JAVA_HOME/bin:$PATH

Don’t forget to replace the “path of java”  with the string that you copied in the above section. In my case, I will paste the following in this file –

export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

Now, look into the image below –

3. Press ctrl+s to save in nano editor and then press ctrl+x to exit from it.

4. Logout and login again or reboot your system, to make changes effective.

Conclusion

The method discussed in this article is among the easiest ones. Now, I hope this article is useful to you. If you would like to say something on this topic you can share your thoughts with us.

Previous How To Install Ubuntu 20.04 LTS?
Next Static Hosting With AWS and user-friendly URLs

About author

You might also like

Uncategorized 0 Comments

How To Change Default Settings Of Grub Bootloader?

Contents1 Grub2 Make Changes Through Your Terminal2.1 Backup the current configuration file-2.2 Make Changes-2.3 Update the grub-3 Make changes by using Gurb-Customizer3.1 Add repository-3.2 Install the grub-customizer –3.3 Remove grub-customizer

Uncategorized 0 Comments

What Is apt-fast And Why Should You Use It?

This post was last updated on January 2nd, 2020 at 03:46 pmContents1 What is apt-fast?2 How to install it?3 How to use it? What is apt-fast? apt-fast is a shell

Uncategorized 0 Comments

How To Count Words, Lines, of A File with wc command In Linux/Unix?

While working with files especially with text files sometimes you may need to count the number of words, number of lines, total character, etc. Linux/Unix provides wc command which is

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply