如何在Linux中设置Java主目录路径?

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.

JDKJRE有两个主要的不同版本。 最初的供应商是Oracle,它分发和设置Java标准。 其次是Oracle支持的JDK和JRE的开放版本。 在本文中,我们将安装名为openjdk-9-jre-headless的开放版本。

$ sudo apt-get install openjdk-9-jre-headless -y
Installation
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
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
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
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
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
Make Java Home Configuration Persistent
使Java Home配置永久存在
LEARN MORE  Java JDK vs JRE What Are Differences and Similarities?
了解更多Java JDK与JRE的区别和相似之处是什么?

翻译自: https://www.poftut.com/how-to-set-java-home-path-in-linux/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值