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](https://stackoverflow.com/questions/16271316/setting-java-home-classpath-in-centos-6)

[How to Install Apache Tomcat 8.5 on CentOS 7.3](https://www.howtoforge.com/tutorial/how-to-install-tomcat-on-centos/)

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:

1. I checked the location of the 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)
3. 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.

4. 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?