我在顶级托管公司购买了 VPS。我是 Linux 新手。由于我无法购买 CPanel 许可证,因此我需要手动安装 JDK、Tomcat 和 MariaDB。所有这一切都通过使用 PUTTY 的 SSH。
有我遵循的教程:
Setting JAVA_HOME & CLASSPATH in CentOS 6
How to Install Apache Tomcat 8.5 on CentOS 7.3
但由于我是 Linux 新手,所以只能安装 JDK8。
现在我需要在 bash 文件中设置 JAVA_HOME 以保持永久不变,然后才能继续安装 tomcat。
从 PUTTY,我以 root 用户身份使用我的密码登录:
我检查了 Java
"which java"的位置:/usr/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/java)我通过命令
"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"
(1) Another program may be editing the same file. 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.
If this is the case, use ":recover" or "vim -r /etc/profile.d/java.sh"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/etc/profile.d/.java.sh.swp"
to avoid this message.
Swap file "/etc/profile.d/.java.sh.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
我按 d
删除现有的。
- 我复制并粘贴:
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
然后我按 ENTER
文件处于插入模式,所以我按 Esc :w java.sh
保存并退出。
然后我关闭 PUTTY session 并再次开始检查 JAVA_HOME 是否已设置:"echo $JAVA_HOME"
没有结果!
我又不知道该怎么办了。我一直重复这两天。请问,有什么帮助吗?
最佳答案
在将其添加到 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
然后运行echo $JAVA_HOME
关于java - Centos中Apache Tomcat如何设置JAVA_HOME?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46837147/