How to set JAVA_HOME in Linux for all users
find /usr/lib/jvm/java-1.x.x-openjdk
vim /etc/profile
Prepend sudo if logged in as not-privileged user, ie.
sudo vim
- Press 'i' to get in insert mode
add:
export JAVA_HOME="path that you found"
export PATH=$JAVA_HOME/bin:$PATH- logout and login again, reboot, or use
source /etc/profile
to apply changes immediately in your current shell
JAVA_HOME directory in Linux
echo $JAVA_HOME
will print the value if it's set. However, if you didn't set it manually in your startup scripts, it probably isn't set.
If you try which java
and it doesn't find anything, Java may not be installed on your machine, or at least isn't in your path. Depending on which Linux distribution you have and whether or not you have root access, you can go to http://www.java.com to download the version you need. Then, you can set JAVA_HOME to point to this directory. Remember, that this is just a convention and shouldn't be used to determine if java is installed or not.
Find JAVA_HOME and set it on RHEL
First, try echo $JAVA_HOME
from the command line. Since java
is on your path already, JAVA_HOME
may be set.
What is the best way to figure out the installation directory of my java installation
Running the command which java
will point you to where java
is installed.
and then set JAVA_HOME
You can edit ~/.bashrc
, ~/.bash_profile
, or /etc/profile
to set JAVA_HOME
. Setting it in ~/etc/profile
will set it system wide, and this is probably not what you want. Say for the sake of example the output of which java
is /opt/jdk_1.7.0_25
, then you'd just add export JAVA_HOME=/opt/jdk_1.7.0_25
to ~/.bashrc
or ~/.bash_profile
and then run source ~/.bashrc
(or source ~/.bash_profile
if you set it there).
Note that in this case, java
is on the PATH
but in some cases you'd need to add export PATH=$PATH:$JAVA_HOME/bin
to add the JAVA_HOME
variable to the PATH
.
How to set Java environment path in Ubuntu
set environment variables as follows
Edit the system Path file /etc/profile
sudo gedit /etc/profile
Add following lines in end
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
Then Log out and Log in ubuntu for setting up the paths...
How to clear the JAVA_HOME in linux
Simply spoken, there is a whole hierarchy of configuration files that might have been updated in the past and that contain that setup.
There could bee a local .profile, .bashrc; or system-wide pendants for you. So, depending on the shell you are using, the version of Linux, ... there are various places to look at. See here for some guidance with bash.
You can start with a simple
grep JAVA_HOME .*
in your home directory. Next level of "escalation":
/etc/environment, /etc/profile, /etc/profile.d/, /etc/bashrc
What is the correct target for the JAVA_HOME environment variable for a Linux OpenJDK Debian-based distribution?
What finally worked for me (Grails now works smoothly) is doing almost like Steve B. has pointed out:
JAVA_HOME=/usr/lib/jvm/default-java
This way if the user changes the default JDK for the system, JAVA_HOME
still works.
default-java
is a symlink to the current JVM.
JAVA not in path although JAVA_HOME set
Specifically for OpenBSD6.0, add
export JAVA_HOME=/usr/local/jdk-1.8.0/
to your .profile
.
This specific version of the jdk, and possibly the basic path itself is subject to change in subsequent and previous versions of OpenBSD, you have been warned.
Related Topics
Sending Command to Java -Jar Using Stdin via /Proc/{Pid}/Fd/0
Ugly Fonts in Java Applications on Ubuntu
Spring Data JPA Deleteby Query Not Working
In Linux, How to Execute Java Jar File with External Jar Files
Random Noclassdeffound Error in Web Application
Java.Lang.Outofmemoryerror: Java Heap Space
Jfilechooser and Browsing Networked MAChines
Can't Run Program with Processbuilder, Runs Fine from Command Line
How to Add Multiple Jar Files in Classpath in Linux
How to Support Both Ipv4 & Ipv6 on Java
No Swt-Mozilla-Gtk-4332 in Java.Library.Path
Using Xdg Directory Specification on Java Application
How to Create a Linux Cluster for Running Physics Simulations in Java
Runtime Exception Not Terminating the Programm
Org.Apache.Commons.Net.Ftp.Parser.Parserinitializationexception: Unknown Parser Type: Linux