Set $JAVA_HOME in Linux

Software Engineering Team Lead and Director of Cloudsure
$JAVA_HOME an environment variable. It is the root path of the JRE or JDK which some applications and services use to access Java.
I know that Java is installed java -version but its not in the path
echo $JAVA_HOME, the output is empty.
Configure for single user
-
Open the shell script in your favorite editor eg.
vim ~/.zshrcvim ~/.bashrc -
Add this line to export the path the the corresponding directory
export JAVA_HOME=/usr/bin/javawhich can be determined usingwhich javaif you are unsure. -
Add the path to $PATH
export $PATH=$PATH:$JAVA_HOME -
Save the file.
-
Source the file in your terminal eg.
source ~/.zshrcorsource ~/.bashrc -
Execute
echo $JAVA_HOMEto verify the output.
Configure for all users
-
Login a root or use
sudoto execute commands. -
Execute bash
sudo bash -
Edit
vim /etc/bashrcorvim /etc/profile -
Add
export JAVA_HOME=/usr/bin/java -
Save the file.
-
Source
source /etc/bashrcorsource /etc/profile -
Echo
echo $JAVA_HOME -
exitto exit the sudo bash terminal.
References
- What is the purpose of .bashrc and how does it work? - UNIX StackExchange
- Setting JAVA_HOME - Atlassian Opsgenie
- How to Set JAVA_HOME / PATH variables Under Linux Bash Profile - nixCraft


