Overview:

As a Java-based framework, your SpringBoot development environment and deployment environment must have the JAVA_HOME and JRE_HOME environment variables configured correctly.

The following will take you through the general CentOS 7.x Java installation, and focus on how to set these environment variables, and verify they are pointing to the Java distribution.

Prerequisites:

  • General Linux administrative and command knowledge
  • sudo privileges on the target CentOS system, as we shall be installing and configuring software
  • FTP client, either at your remote desktop workstation, or on the target CentOS system
  • A recent yum -update is always helpful
  • I also recommend taking a snapshot of your target development CentOS virtual machine before installing major software components or adjusting critical configuration settings.
  • See disclaimer

1. Installation Procedure:

  1. Make a working directory to download the latest Java distribution:
    cd /opt 
    mkdir java
  2. At your workstation, download the latest version of java SE RPM.
    > At the time of this article, this is jdk-8u151-linux-x64.rpm
    > At the time of this article, the download url is:
    http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.rpm
  3. Using your FTP client of choice, download the rpm to /opt/java
  4. Return to the dev server SSH console. Install the rpm using yum as follows:
    cd /opt/java
    yum localinstall jdk-8u151-linux-x64.rpm
    
    

2. Adding JAVA_HOME and JRE_HOME to /etc/bashrc

  1. Using nano, open /etc/bashrc to add the following java environment variables.
    nano /etc/bashrc 
    
  2. Scroll to bottom of the /etc/bashrc file.
  3. Add the following lines to set the JAVA_HOME and JRE_HOME environment variables to the /usr/bin location. The yum rpm install above set a series of symbolic links in the /etc/alternatives which were also set in /usr/lib … the full path is:
    /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el6_9.x86_64/jre
    ...
    
    # Java and JRE
    export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el6_9.x86_64/jre
    export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el6_9.x86_64/jre
    PATH=$PATH:$JAVA_HOME:$JRE_HOME
    
    
  4. Reload your bash environment settings, including the new path variables, by:
    source /etc/bashrc
    
  5. Test your java environment. At prompt type the following:
    java -version
    echo $JRE_HOME
    echo $JAVA_HOME
    

And that’s it. The console should now display your paths to Java, which will allow you to execute java -jar to load your SpringBoot executables. Thanks, Like and Link! paulsDevBlog.End();