Java is a popular programming language and framework in the IT industry. There are a lot of applications developed with Java. Java requires Java Development Kit to develop applications. Compiled java applications can run on systems those are installed Java Runtime Environment a.k.a JRE. We will look in this post on how to set and check JRE or JDK or Java Home Path.
Java是IT行业中流行的编程语言和框架。 有许多用Java开发的应用程序。 Java需要Java Development Kit来开发应用程序。 编译的Java应用程序可以在已安装Java Runtime Environment或JRE的系统上运行。 我们将在这篇文章中介绍如何设置和检查JRE或JDK或Java Home Path。
安装 (Installation)
There are two main different versions of JDK and JRE. The original vendor is Oracle which distributes and sets standards of Java. Second is an open version of JDK and JRE that are supported by Oracle. In this post, we will install the open version named as openjdk-9-jre-headless.
JDK和JRE有两个主要的不同版本。 最初的供应商是Oracle,它分发和设置Java标准。 其次是Oracle支持的JDK和JRE的开放版本。 在本文中,我们将安装名为openjdk-9-jre-headless的开放版本。
$ sudo apt-get install openjdk-9-jre-headless -y
Installation
安装
检查Java状态(Check Java Status)
We will look if java path already sets simple running java command which is a compiler for Java applications.
我们将查看java路径是否已经设置了简单运行的java命令,该命令是Java应用程序的编译器。
$ java
Check Java Status
检查Java状态
更新定位数据库(Update Locate Database)
This is auxiliary operation to use locate OpenJDK location we update locate database
这是使用locate OpenJDK位置的辅助操作,我们将更新locate数据库
$ sudo updatedb
查找JDK位置 (Find JDK Location)
We will look at where is JDK located and also get the JDK version. This operation can be used Oracle JDK too. Just the JDK directory name will be different.
我们将查看JDK的位置,并获取JDK版本。 该操作也可以用于Oracle JDK。 只是JDK目录名称会有所不同。
$ locate openjdk
Find JDK Location
查找JDK位置
设置Java主页(Set Java Home)
As we see there is a lot of output for JDK search we can see that the path of JDK is /usr/lib/jvm/java-9-openjdk-amd64 because it is located in usr lib. Now we will set PATH for Java
正如我们看到的,JDK搜索有很多输出,我们可以看到JDK的路径是/usr/lib/jvm/java-9-openjdk-amd64因为它位于usr lib中。 现在我们将为Java设置PATH
$ export JAVA_HOME="/usr/lib/jvm/java-9-openjdk-amd64"
Set Java Home
设置Java主页
使Java Home配置永久存在(Make Java Home Configuration Persistent)
The previous step makes JAVA HOME available for subshells but if the system is restarted the path will be lost. So we need to make this path definition persistent. There are different methods to make persistent. We will look single and simple one. We will add path definition to the system-wide environment definition configuration. This operation requires root privileges.
上一步使JAVA HOME可用于子外壳,但是如果系统重新启动,则路径将丢失。 因此,我们需要使该路径定义持久化。 有多种方法可以使持久化。 我们将看起来很简单。 我们将路径定义添加到系统范围的环境定义配置中。 此操作需要root特权。
$ echo "JAVA_HOME='/usr/lib/jvm/java-9-openjdk-amd64'" >> /etc/environment
Make Java Home Persistent
使Java永久存在
An alternative method without the need for root privileges is adding Java home path definition to the normal user .bashrc file like below.
不需要root特权的另一种方法是将Java主目录定义添加到普通用户.bashrc文件中,如下所示。
$ echo "JAVA_HOME='/usr/lib/jvm/java-9-openjdk-amd64'" >> .bashrc
Make Java Home Configuration Persistent
使Java Home配置永久存在
.u1fe8f9987fa7cf54450d0166501a06e1 , .u1fe8f9987fa7cf54450d0166501a06e1 .postImageUrl , .u1fe8f9987fa7cf54450d0166501a06e1 .centered-text-area { min-height: 80px; position: relative; } .u1fe8f9987fa7cf54450d0166501a06e1 , .u1fe8f9987fa7cf54450d0166501a06e1:hover , .u1fe8f9987fa7cf54450d0166501a06e1:visited , .u1fe8f9987fa7cf54450d0166501a06e1:active { border:0!important; } .u1fe8f9987fa7cf54450d0166501a06e1 .clearfix:after { content: ""; display: table; clear: both; } .u1fe8f9987fa7cf54450d0166501a06e1 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .u1fe8f9987fa7cf54450d0166501a06e1:active , .u1fe8f9987fa7cf54450d0166501a06e1:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .u1fe8f9987fa7cf54450d0166501a06e1 .centered-text-area { width: 100%; position: relative; } .u1fe8f9987fa7cf54450d0166501a06e1 .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u1fe8f9987fa7cf54450d0166501a06e1 .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u1fe8f9987fa7cf54450d0166501a06e1 .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u1fe8f9987fa7cf54450d0166501a06e1:hover .ctaButton { background-color: #E67E22!important; } .u1fe8f9987fa7cf54450d0166501a06e1 .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .u1fe8f9987fa7cf54450d0166501a06e1 .u1fe8f9987fa7cf54450d0166501a06e1-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u1fe8f9987fa7cf54450d0166501a06e1:after { content: ""; display: block; clear: both; }
LEARN MORE Java JDK vs JRE What Are Differences and Similarities?
.u1fe8f9987fa7cf54450d0166501a06e1 , .u1fe8f9987fa7cf54450d0166501a06e1 .postImageUrl , .u1fe8f9987fa7cf54450d0166501a06e1 .centered-text-area { min-height: 80px; position: relative; } .u1fe8f9987fa7cf54450d0166501a06e1 , .u1fe8f9987fa7cf54450d0166501a06e1:hover , .u1fe8f9987fa7cf54450d0166501a06e1:visited , .u1fe8f9987fa7cf54450d0166501a06e1:active { border:0!important; } .u1fe8f9987fa7cf54450d0166501a06e1 .clearfix:after { content: ""; display: table; clear: both; } .u1fe8f9987fa7cf54450d0166501a06e1 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .u1fe8f9987fa7cf54450d0166501a06e1:active , .u1fe8f9987fa7cf54450d0166501a06e1:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .u1fe8f9987fa7cf54450d0166501a06e1 .centered-text-area { width: 100%; position: relative; } .u1fe8f9987fa7cf54450d0166501a06e1 .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u1fe8f9987fa7cf54450d0166501a06e1 .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u1fe8f9987fa7cf54450d0166501a06e1 .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u1fe8f9987fa7cf54450d0166501a06e1:hover .ctaButton { background-color: #E67E22!important; } .u1fe8f9987fa7cf54450d0166501a06e1 .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .u1fe8f9987fa7cf54450d0166501a06e1 .u1fe8f9987fa7cf54450d0166501a06e1-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u1fe8f9987fa7cf54450d0166501a06e1:after { content: ""; display: block; clear: both; }
了解更多Java JDK与JRE的区别和相似之处是什么?
翻译自: https://www.poftut.com/how-to-set-java-home-path-in-linux/
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。