How to Set Java_home in Linux

Rashmi Patidar Feb 02, 2024
How to Set Java_home in Linux

Below are steps to set JAVA_HOME in Linux.

  • Open terminal or console in Linux.
  • Check if the Java home is already in the correct place. Use command echo $JAVA_HOME to view the current value. It will print the system variable named JAVA_HOME. The path variable is not set if nothing comes in output.
  • Prerequisite to set the JAVA_HOME variable is, JDK should already get installed on the machine.
  • On the terminal, execute the vi ~/bash_profile or vi ~/bashrc command. vi command is used to open a file in the editor mode. Tilde represented as ~ represents a home directory. The command follows with a slash / and bash_profile that is the filename. So the file opens in editing mode with the following command.
  • Press i to go to insert mode in the vi editor screen.
  • Add export JAVA_HOME=/usr/java/jdk1.8.0_191 and export PATH=$JAVA_HOME/bin:$PATH to end of the file.
  • Press Ctrl+C to exit the insert mode.
  • Save the recently made changes using the :wq command. The command will save the file and quit the vi editor.
  • Close the current running tab to reboot the changes made.
  • Open the terminal and check JAVA_HOME using the echo $JAVA_HOME command.
Rashmi Patidar avatar Rashmi Patidar avatar

Rashmi is a professional Software Developer with hands on over varied tech stack. She has been working on Java, Springboot, Microservices, Typescript, MySQL, Graphql and more. She loves to spread knowledge via her writings. She is keen taking up new things and adopt in her career.

LinkedIn

Related Article - Java Javac