top of page
  • Nikhila Jain

Set JAVA_HOME on Windows, Mac, Linux and Unix

Java is one of the most popular programming languages in the world and is widely used in various applications and systems. One of the important steps in setting up and running Java applications is to set the JAVA_HOME environment variable. This variable tells the system where the Java runtime environment (JRE) is installed on your machine.


In this blog post, you will learn how to set JAVA_HOME on different operating systems such as Mac, Windows, Linux, and Unix.


Mac

Follows the steps below to setup JAVA_HOME on your Mac:

  • Open Terminal.

  • Run the command to open the .bash_profile file in the vi editor.

	 "vi ~/.bash_profile" 
  • Add the following line to the file:

	export JAVA_HOME=$(/usr/libexec/java_home)
  • Save the file and exit the editor.

  • Run the command to reload the .bash_profile file.

source ~/.bash_profile
  • Verify that JAVA_HOME is set by running the command "echo $JAVA_HOME".

Windows

Follows the steps below to setup JAVA_HOME on your Windows:

  • Open the Start menu and type "Environment Variables" in the search bar.

  • Click on "Edit the system environment variables".

  • Click on the "Environment Variables" button.

  • Under "User variables", click on the "New" button.

  • Enter "JAVA_HOME" as the variable name and the path to the Java installation as the variable value.

  • Click on "OK" to save the changes.

  • Verify that JAVA_HOME is set by opening the Command Prompt and running the following command:

echo %JAVA_HOME%

Linux and Unix

Follows the steps below to setup JAVA_HOME on your Linux or Unix machine:

  • Open Terminal.

  • Run the command to open the .bashrc file in the vi editor:

vi ~/.bashrc
  • Add the following line to the file:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
  • Save the file and exit the editor.

  • Run the command to reload the .bashrc file.

source ~/.bashrc
  • Verify that JAVA_HOME is set by running the following command:

echo $JAVA_HOME

In conclusion, setting JAVA_HOME is an essential step in running Java applications on your machine. The process of setting JAVA_HOME is slightly different for different operating systems, but it is straightforward and can be done in a few simple steps. Remember to verify that JAVA_HOME is set correctly by running the appropriate command for your operating system.


Happy coding!



Post: Blog2 Post
bottom of page