简体   繁体   English

在Centos7中设置JAVA_HOME

[英]Setting JAVA_HOME in Centos7

I have purchased a VPS with a top hosting company. 我已经与顶级托管公司购买了VPS。 I am new to Linux. 我是Linux新手。 Since I am not able to purchase a CPanel License, I need to manually install JDK, Tomcat, and MariaDB. 由于我无法购买CPanel许可证,因此需要手动安装JDK,Tomcat和MariaDB。 All this through SSH using PUTTY. 所有这些都通过使用PUTTY的SSH进行。

There are tutorials which I have followed: 我遵循了一些教程:

Setting JAVA_HOME & CLASSPATH in CentOS 6 在CentOS 6中设置JAVA_HOME和CLASSPATH

How to Install Apache Tomcat 8.5 on CentOS 7.3 如何在CentOS 7.3上安装Apache Tomcat 8.5

But since I am a newbie in Linux am only able to install JDK8. 但是由于我是Linux的新手,因此只能安装JDK8。

Now I need to set JAVA_HOME in a bash file to remain permanent before I can continue with tomcat installation. 现在,我需要在bash文件中设置JAVA_HOME才能保持永久性,然后才能继续安装tomcat。

From PUTTY, I have login as root user with my password: 在PUTTY中,我以root用户身份使用密码登录:

  1. I checked the location of the Java "which java" : /usr/bin/java 我检查了Java "which java" : /usr/bin/java

  2. To get the exact jdk name I used command "sudo update-alternatives --config java" >java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64/jre/bin/java) 为了获得确切的jdk名称,我使用了命令"sudo update-alternatives --config java" > java-1.8.0-openjdk.x86_64(/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0 .b01.el7_4.x86_64 / JRE / bin中/爪哇)

  3. I create a new file through command "vim /etc/profile.d/java.sh" which gave below error 我通过命令"vim /etc/profile.d/java.sh"创建了一个新文件,该文件出现以下错误

    E325: ATTENTION Found a swap file by the name "/etc/profile.d/.java.sh.swp" owned by: root dated: Thu Oct 19 14:21:28 2017 file name: /etc/profile.d/java.sh modified: YES user name: root host name: rtp process ID: 31766 While opening file "/etc/profile.d/java.sh" E325:注意找到了一个名为“ /etc/profile.d/.java.sh.swp”的交换文件,该文件拥有:root日期:Thu Oct 19 14:21:28 2017文件名:/etc/profile.d/修改java.sh:是用户名:根主机名:rtp进程ID:31766打开文件“ /etc/profile.d/java.sh”时

    (1) Another program may be editing the same file. (1)另一个程序可能正在编辑同一文件。 If this is the case, be careful not to end up with two different instances of the same file when making changes. 在这种情况下,进行更改时请注意不要以同一文件的两个不同实例结尾。 Quit, or continue with caution. 退出,或继续谨慎。 (2) An edit session for this file crashed. (2)该文件的编辑会话崩溃。 If this is the case, use ":recover" or "vim -r /etc/profile.d/java.sh" to recover the changes (see ":help recovery"). 在这种情况下,请使用“:recover”或“ vim -r /etc/profile.d/java.sh”恢复更改(请参见“:help recovery”)。 If you did this already, delete the swap file "/etc/profile.d/.java.sh.swp" to avoid this message. 如果已经执行此操作,请删除交换文件“ /etc/profile.d/.java.sh.swp”以避免出现此消息。

    Swap file "/etc/profile.d/.java.sh.swp" already exists! 交换文件“ /etc/profile.d/.java.sh.swp”已存在! [O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: [O]笔只读,(E)仍然删除,(R)发现,(D)删除它,(Q)uit,(A)终止:

I pressed d to delete the existing one. 我按d键删除现有的。

  1. I copy this and pasted: 我复制并粘贴:

    export JAVA_HOME=/usr/bin/java/java-1.8.0-openjdk.x86_64 export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar 导出JAVA_HOME = / usr / bin / java / java-1.8.0-openjdk.x86_64导出PATH = $ PATH:$ JAVA_HOME / bin导出CLASSPATH = $ JAVA_HOME / jre / lib / ext:$ JAVA_HOME / lib / tools.jar

And then I Press ENTER The file is in insert mode so I press Esc :w java.sh to save and exit. 然后按ENTER键该文件处于插入模式,因此按Esc :w java.sh保存并退出。 Then I closed the PUTTY session and started again to check if the JAVA_HOME has been set: "echo $JAVA_HOME" 然后,我关闭PUTTY会话,然后再次开始以检查是否已设置JAVA_HOME: "echo $JAVA_HOME"

No result! 没有结果! I don't understand what to do again. 我不知道该怎么办。 I kept on repeating this for two days now. 我现在重复了两天。 Please, any help? 请帮忙吗?

If your usage is covered by their licence, I strongly recommend to use Oracle's JDK RPM: when installed it provides much more sane directory layout than OpenJDK RPM package(s): you would be able to use "/usr/java/latest" as Java home. 如果您的使用被许可许可,我强烈建议您使用Oracle的JDK RPM:安装后,它提供比OpenJDK RPM软件包更多的合理目录布局:您可以使用“ / usr / java / latest”作为Java之家。 To have persistent environment variable, add export command to ~/.bashrc or ~/.bash_profile file (depending on how you perform remote login, add it to both if unsure): export JAVA_HOME=/usr/java/latest . 要具有持久性环境变量,请将export命令添加到~/.bashrc~/.bash_profile文件中(取决于您执行远程登录的方式,如果不确定,则将其添加到两者中): export JAVA_HOME=/usr/java/latest

Run below commands on shell prompt before adding it into java.sh: 在将其添加到java.sh中之前,在shell提示符下运行以下命令:

export JAVA_HOME=/usr/bin/java/java-1.8.0-openjdk.x86_64 
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar

Then run echo $JAVA_HOME 然后运行echo $JAVA_HOME

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM