In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people have no idea about how to set JAVA_HOME environment variable in Linux. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Problem: I need to compile the Java program on my Linux machine. I've installed JDK (Java Development Kit) for this, and now I'm trying to set the JAVA_HOME environment variable to point to the installed JDK. What is the most popular way to set the JAVA_HOME environment variable on Linux?
Many Java programs or Java-based integrated development environments (IDE) need to set the JAVA_HOME environment variable. This variable should point to the installation directory of the Java Development Kit (JDK) or Java Runtime Environment (JRE). JDK not only contains everything that JRE provides, but also comes with additional binaries and library files (such as compilers, debuggers, and JavaDoc document generators) for compiling Java programs. JDK is used to build Java programs, and a single JRE is sufficient if you just run a Java program that has already been built.
When you are trying to set the JAVA_HOME environment variable, the trouble is that the JAVA_HOME variable needs to change based on (1) whether you have installed JDK or JRE;, (2) which version you installed, and (3) whether you installed Oracle JDK or Open JDK.
So whenever your development or runtime environment changes (for example, an updated version of JDK), you need to adjust the JAVA_HOME variable according to the actual situation, which is onerous and inefficient.
The following export command automatically sets the JAVA_HOME environment variable for you, regardless of the above factors.
If you are installing JRE:
Export JAVA_HOME=$ (dirname $(dirname $(readlink-f $(which java)
If you are installing JDK:
Export JAVA_HOME=$ (dirname $(dirname $(readlink-f $(which javac)
In your case, write one of the above commands to the ~ / .bashrc (or / etc/profile) file, and it will * set the JAVA_HOME variable.
Note that because java or javac can establish multiple levels of symbolic links, the "readlink-f" command is used to get their actual execution path.
For example, if you install Oracle JRE 7, the above export command will automatically set the JAVA_HOME to:
/ usr/lib/jvm/java-7-oracle/jre
If you install Open JDK version 8, the second export command sets the JAVA_HOME to:
/ usr/lib/jvm/java-8-openjdk-amd64
After reading the above, have you mastered how to set the JAVA_HOME environment variable in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.