title: How Do I Set JAVA_HOME in Centos For Apache Tomcat?
body: <p>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.</p>
  <p>There are tutorials which I have followed:</p>
  <p><a href="https://stackoverflow.com/questions/16271316/setting-java-home-classpath-in-centos-6">Setting JAVA_HOME &amp; CLASSPATH in CentOS 6</a></p>
  <p><a href="https://www.howtoforge.com/tutorial/how-to-install-tomcat-on-centos/" rel="nofollow noreferrer">How to Install Apache Tomcat 8.5 on CentOS 7.3</a></p>
  <p>But since I am a newbie in Linux am only able to install JDK8.</p>
  <p>Now I need to set JAVA_HOME in a bash file to remain permanent before I can continue with tomcat installation.</p>
  <p>From PUTTY, I have login as root user with my password:</p>
  <ol>
  <li><p>I checked the location of the Java <code>&quot;which java&quot; : /usr/bin/java</code></p>
  </li>
  <li><p>To get the exact jdk name I used command  <code>&quot;sudo update-alternatives --config java&quot;</code> &gt;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)</p>
  </li>
  <li><p>I createed a new file through command <code>&quot;vim /etc/profile.d/java.sh&quot;</code> which gave the error below:</p>
  </li>
  </ol>
  <pre><code>    E325: ATTENTION
      Found a swap file by the name &quot;/etc/profile.d/.java.sh.swp&quot;
                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 &quot;/etc/profile.d/java.sh&quot;
      
      (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 &quot;:recover&quot; or &quot;vim -r /etc/profile.d/java.sh&quot;
          to recover the changes (see &quot;:help recovery&quot;).
          If you did this already, delete the swap file &quot;/etc/profile.d/.java.sh.swp&quot;
          to avoid this message.
      
      Swap file &quot;/etc/profile.d/.java.sh.swp&quot; already exists!
      [O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
  </code></pre>
  <p>I pressed <code>d</code> to delete the existing one.</p>
  <ol start="4">
  <li>I copy this and pasted:</li>
  </ol>
  <pre><code>    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
  </code></pre>
  <p>And then I Press ENTER</p>
  <p>The file is in insert mode so I press <code>Esc :w java.sh</code> to save and exit.</p>
  <p>Then I closed the PUTTY session and started again to check if the JAVA_HOME has been set: <code>&quot;echo $JAVA_HOME&quot;</code></p>
  <p>No result!</p>
  <p>I don't understand what to do again. I kept on repeating this for two days now. Please, any help?</p>