setting java_home and path environmental variables in linux

14,741

Solution 1

Open ~/.bashrc and add

export JAVA_HOME=<path to your java>
export PATH=<path to your java>:$PATH

with the path where your java is and then reopen terminal or execute source ~/.bashrc

Solution 2

Correct solution is:

  • Open ~/.bashrc file
  • Add to this file 2 lines as below:
export JAVA_HOME=Path_to_Java_installation_folder
export PATH=$JAVA_HOME/bin:$PATH

in the bottom.

Logoff and login again, then check the result.

Solution 3

To setup environment variable just follow some steps from root user:

# vi /etc/profile.d/java.sh

Add the following lines to the java.sh file-

export JAVA_HOME=/usr/java/default
export PATH=$JAVA_HOME/bin:$PATH

After adding those lines to java.sh, save and exit. Then-

# source /etc/profile.d/java.sh

For cassandra environment variable setup: https://stackoverflow.com/a/39940053/4610541

Share:
14,741
Madhuri
Author by

Madhuri

Updated on June 04, 2022

Comments

  • Madhuri
    Madhuri almost 2 years

    I downloaded java-8 and amd combined package for working with Cassandra in linux. When I run cassandra, it is showing as- Unable to find java executable. Check JAVA_HOME and PATH environment variables.

    How to correctly set those variables?

  • Madhuri
    Madhuri over 7 years
    what do java_home and path variables exactly resemble and how should we set them?
  • Philip Voronov
    Philip Voronov over 7 years
    you set them like i said, these are environment variables that resemble paths where programs will try to find your java.
  • Madhuri
    Madhuri over 7 years
    permissions denied.. is there any other option?
  • Philip Voronov
    Philip Voronov over 7 years
    yes, execute it in your terminal, but you will need to execute it every time you reopen terminal (changing .bashrc does it instead of you)
  • Anil Nivargi
    Anil Nivargi about 5 years
    Thanks.... helped me