【发布时间】:2018-03-31 22:04:18
【问题描述】:
我在一家顶级托管公司购买了 VPS。我是 Linux 新手。由于我无法购买 CPanel 许可证,我需要手动安装 JDK、Tomcat 和 MariaDB。所有这一切都通过 SSH 使用 PUTTY。
我遵循了一些教程:
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 会话并重新开始检查 JAVA_HOME 是否已设置:"echo $JAVA_HOME"
没有结果!
我不明白该怎么做。这两天我一直在重复这个。请问有什么帮助吗?
【问题讨论】:
标签: java linux bash tomcat vim