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:
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"
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
gedit ~/.pam_environment But it is completely empty
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".
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?
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
                        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:
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.
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.
Then edit your ~/.bashrc file and add the following line:
export JAVA_HOME="/usr/lib/jvm/java-8-oracle/". 
Either restart your terminal, or type bash.
This should set the JAVA_HOME environment variable.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With