I have purchased a VPS with a top hosting company. I am new to Linux. Since I am not able to purchase a CPanel License, I need to manually install JDK, Tomcat, and MariaDB. All this through SSH using PUTTY.
There are tutorials which I have followed:
Setting JAVA_HOME & CLASSPATH in CentOS 6
How to Install Apache Tomcat 8.5 on CentOS 7.3
But since I am a newbie in Linux am only able to install JDK8.
Now I need to set JAVA_HOME in a bash file to remain permanent before I can continue with tomcat installation.
From PUTTY, I have login as root user with my password:
-
I checked the location of the Java
"which java" : /usr/bin/java
-
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) -
I createed a new file through command
"vim /etc/profile.d/java.sh"
which gave the error below:
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:
I pressed d
to delete the existing one.
- 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
And then I Press ENTER
The file is in insert mode so I press Esc :w java.sh
to save and exit.
Then I closed the PUTTY session and started again to check if the JAVA_HOME has been set: "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?
2
Answers
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.
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
.Run below commands on shell prompt before adding it into java.sh:
Then run
echo $JAVA_HOME