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
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...
Setting JAVA_HOME on centos for root and normal user -- checking java -version
Because you installed java in /usr/lib
, this folder is in system environment. When you type java -version
, the system can find the command java
.
But if you install java in other folder not in system environment, you must set the JAVA_HOME
PATH in /etc/profile
to tell the system how to find the java
command, and there are other important reasons why to set the JAVA_HOME
not just for this.
https://stackoverflow.com/a/27996647/11559693
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
.
Related Topics
What Are the Pros and Cons of the Leading Java HTML Parsers
What's the Best Way to Share Data Between Activities
What Is the Most Appropriate Way to Store User Settings in Android Application
Why Do I Get "Failed to Bounce to Type" When I Turn Json from Firebase into Java Objects
Do Line Endings Differ Between Windows and Linux
Why Is Char[] Preferred Over String For Passwords
Variable Might Not Have Been Initialized Error
What Causes Error "No Enclosing Instance of Type Foo Is Accessible" and How to Fix It
When Is the Finalize() Method Called in Java
Converting HTML to Pdf Using Itext
How to Call a Soap Web Service on Android
Can't Create Directory in Android 10
Failed to Resolve Com.Google.Android.Gms Play-Services-Auth:11.4.0
Javafx on Linux Is Showing a "Graphics Device Initialization Failed For: Es2, Sw"
How to Deal With "Java.Lang.Outofmemoryerror: Java Heap Space" Error