How to Set Java_Home in Linux For All Users

How to set JAVA_HOME in Linux for all users

  1. find /usr/lib/jvm/java-1.x.x-openjdk
  2. vim /etc/profile

    Prepend sudo if logged in as not-privileged user, ie. sudo vim

  3. Press 'i' to get in insert mode
  4. add:

    export JAVA_HOME="path that you found"

    export PATH=$JAVA_HOME/bin:$PATH
  5. 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



Leave a reply



Submit