In this guide, you will learn to Set Java Home PATH on Centos 7. Setting the JAVA_HOME environment variable on Centos 7 is important for several reasons:
- Java Development
- Execution of Java Programs
- System Configuration
- Integration with Other Tools
- Multiple Java Versions
Here you can follow this guide to set up the Java environment path on Centos 7.
Quickly Learn To Set Java Home PATH on Centos 7
To complete this guide, you must access your server as a non-root user with sudo privileges. For this purpose, you can check the Centos 7 Initial Setup Guide.
Also, we assumed that you have a Java version installed on your server.
Now follow the steps below to start your Java_Home Path setup on Ventos 7.
Step 1 – Find Java Installation Directory on Centos 7
At this point, you can verify your Java installation by checking its version:
java --version
Then, you need to locate your Java installation path folder on Centos 7. To do this, run the command below:
sudo update-alternatives --config java
In this example, we get the following output:
Output
/usr/lib/jvm/jdk-21-oracle-x64/bin/java
Note: If you have multiple versions of Java, you can easily get the path of them with the following command.
Step 2 – Setting up Java Home PATH on Centos 7
Once you found your installation path folder, you can easily set your Java home path. To do this, open the bashrc file with your desired text editor like Vi editor or Nano editor:
sudo vi ~/.bashrc
At the end of the file, add the following line with your Java installation directory:
export PATH="/path/to/java/bin:$PATH"
In this example, it looks like this:
export PATH="/usr/lib/jvm/jdk-21-oracle-x64/bin/java:$PATH"
When you are done, save and close the file.
Then, apply the changes with the command below:
sudo source ~/.bashrc
You can verify that the Java PATH variable is set correctly by running the command below:
echo $PATH
Output
/usr/lib/jvm/jdk-21-oracle-x64/bin/java:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
That’s it, you are done.
Conclusion
Setting the JAVA_HOME environment variable on CentOS 7 is essential for Java development and ensures that Java-based applications, tools, and services function correctly and use the intended Java runtime environment. At this point, you have learned to locate your Java installation path folder and easily set up the environment path on Centos 7. Hope you enjoy it.
Also, you may like to read the following articles:
Set Java PATH Variable on Ubuntu 22.04 Permanently