Install Java 8 on CentOS 7
In this tutorial, we’ll be showing you how to install Oracle’s Java 8 programming language specifically onto a CentOS 7 server. This simple object-oriented language is used for many of the applications and websites you come across today. Let’s jump right in!
Pre-flight
- Open the terminal and login as root. If you are logged in as another user, you will need to add sudo before each command.
- Working on a Linux CentOS 7 VPS server
- No installations of previous Java versions
Installing Java 8 on CentOS 7
Step 1: Update
As a matter of best practice we’ll update before installing any new programs:
yum -y update
Step 2: Install Java 8
yum install java-1.8.0-openjdk
Step 3: Verify Java is Installed
java -version
Example Output:
java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Set Java’s Home Environment
Step 1: Find Java’s Path
Let’s set the JAVA_HOME variable, using the following command will give us a path so we can set the variable.
update-alternatives --config java
You’ll see a prompt to “Enter to keep the current selection[+], or type selection number:”, if you had multiple Java version you could set the default here, but all we need is the path of Java so we can exit pressing enter. The highlighted area is the path we will need to copy/paste into our .bash_profile file.
Selection Command
-----------------------------------------------
*+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java)</code?
Step 2: Setting Java’s Path in Your Environment
After copying your Java’s path, open the .bash_profile with your text editor.
vim .bash_profile
Export your Java path into the .bash_profile by adding the following to the bottom of the file. (Your path may look different from mine, and it’s not important that they vary.)
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java
Refresh the File:
Source .bash_profile
When you use the JAVA_HOME variable you’ll now be able to see the path you set.
echo $JAVA_HOME
Example Output:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java
Need Assistance? Reach Out to Our Team
Liquid Web is ready to help you install your programming language on a dedicated server, VPS, and more. Contact our support team to get started now.
Related Articles:
- What is CentOS? Everything You Need to Know
- Check Apache Status with systemctl status and apachectl status Commands
- How to Find the Server Name Indication (SNI) Supporting Details
- How to Install Pip on CentOS 7
- Get Kernel Version for Linux: A Guide
- What Is a Time Series Database? How It Works & Use Cases

About the Author: Echo Diaz
Throughout Echo's four year stint as a technical support specialist, her passion for breaking down complex concepts had to lead to a career in professional writing. As a former top tier support specialist, she added a distinctive element to her written work that spoke to customer feedback and concerns. Echo occasionally pops her head out from behind her computer to watch her dog energetically run around the yard and unabashedly shovels money into buying tickets to see her favorite musical artists.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
ChatGPT Integration — How to Create a Plugin for ChatGPT
Read ArticleWhat is CentOS? Everything You Need to Know
Read ArticleWhat is CentOS? Everything You Need to Know
Read ArticleRedis as Cache: How It Works and Why You Should Use It
Read ArticleRefer-a-Friend Program for Website Hosting: Get $100 for Each Friend!
Read Article