Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu: where is java_home environment variable stored

I have installed java by these commands:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sudo update-java-alternatives -s java-7-oracle

If I understood properly these commands above garantee that java will update automatically. I have been using Eclipse, STS and Tomcat successfully, then I believe that java is properly installed with its environments.

But I want to know where is the java_home environment. I tried:

  1. gedit /etc/environment I found:

    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$GRADLE_HOME/bin"
    GRADLE_HOME="/opt/gradle/gradle-1.6"
    
  2. whereis java (I believe that this is just a file find)

    java: /usr/bin/java /usr/bin/X11/java /usr/share/java /usr/share/man/man1/java.1.gz
    
  3. gedit ~/.pam_environment But it is completely empty

  4. gedit ~/.bashrc and after gedit .profile (I believe that this is just script files that run while starting linux). But I didn't find any string with "java".

  5. printenv JAVA_HOME (I believe that this only prints variables set by export and it is valid only for the exact session you set) But nothing has printed.

I am new to Linux. Could someone help me find where is the java environment in my system and please adjust any wrong believes I wrote before?

like image 825
DemeCarv Avatar asked Jun 22 '13 16:06

DemeCarv


3 Answers

You can use

grep JAVA_HOME /etc/environment /etc/bash.bashrc /etc/profile.d/* /etc/profile

In my case after installing java from webupd8team ppa in Ubuntu 18.04 the scripts with setting and exporting JAVA_HOME variable are located in

/etc/profile.d/jdk.csh:setenv JAVA_HOME /usr/lib/jvm/java-8-oracle
/etc/profile.d/jdk.sh:export JAVA_HOME=/usr/lib/jvm/java-8-oracle
like image 126
nss201 Avatar answered Sep 30 '22 23:09

nss201


When installing java with the webupd8team ppa you will need to set the JAVA_HOME environment variable yourself. You can do this in many ways. How I did it is as follows:

  1. Run the sudo update-alternatives --config java command to get the list of java installations. It will also display the location of the java executable. e.g. /usr/lib/jvm/java-8-oracle/jre/bin/java.

  2. From the java installation that you use select the path up to jre. e.g. /usr/lib/jvm/java-8-oracle/. This will become your JAVA_HOME path.

  3. Then edit your ~/.bashrc file and add the following line: export JAVA_HOME="/usr/lib/jvm/java-8-oracle/".

  4. Either restart your terminal, or type bash.

This should set the JAVA_HOME environment variable.

like image 30
joerideg Avatar answered Oct 01 '22 01:10

joerideg


I don't have an Ubuntu with Java right now, but I've done this in the past. http://www.janosgyerik.com/installing-java-and-setting-java_home-in-ubuntu/

Edit /etc/jvm, add this line to the top of the list: /path/to/your/jvm, which in your case is probably: /usr/lib/jvm/java-7-oracle but you have to check, maybe locatejava-7-oracle` might help.

Thanks to the above step, the java executable will find the right version of Java. You can confirm this by running the command:

java -version

However, setting JAVA_HOME is a different matter. These commands worked in my older version of Ubuntu to detect + set + confirm JAVA_HOME:

. /usr/share/java-common/java-common.sh
eval $(jvm_config)
export JAVA_HOME
echo $JAVA_HOME

If the output looks good, then add these lines to your ~/.bashrc or ~/.profile.

like image 24
janos Avatar answered Oct 01 '22 01:10

janos