I am using Fedora(actually Pidora since I am trying to set up hadoop on a cluster of raspberrypi). I installed oopenjdk on all of the nodes using ansible. However, when I tried to set up the JAVA_HOME environment variable, I got really confused looking at the folder of /usr/lib/jvm
:
[root@datafireball1 jvm]# ls
java-1.7.0-openjdk-1.7.0.60-2.4.7.0.fc20.arm jre jre-1.7.0 jre-1.7.0-openjdk jre-1.7.0-openjdk-1.7.0.60-2.4.7.0.fc20.arm jre-openjdk
[root@datafireball1 jvm]# ls -alth
total 80K
drwxr-xr-x 3 root root 4.0K Jun 7 21:07 .
lrwxrwxrwx 1 root root 35 Jun 7 21:07 jre-1.7.0-openjdk -> /etc/alternatives/jre_1.7.0_openjdk
lrwxrwxrwx 1 root root 27 Jun 7 21:07 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx 1 root root 29 Jun 7 21:07 jre-openjdk -> /etc/alternatives/jre_openjdk
lrwxrwxrwx 1 root root 21 Jun 7 21:07 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root 48 Jun 7 21:07 jre-1.7.0-openjdk-1.7.0.60-2.4.7.0.fc20.arm -> java-1.7.0-openjdk-1.7.0.60-2.4.7.0.fc20.arm/jre
drwxr-xr-x 4 root root 4.0K Jun 7 21:06 java-1.7.0-openjdk-1.7.0.60-2.4.7.0.fc20.arm
Why there are so many folders for Java and which folder should I use as the Java home?
[root@datafireball1 bin]# which java
/usr/bin/java
[root@datafireball1 bin]# ls -alSh /usr/bin/ | grep java
lrwxrwxrwx 1 root root 22 Jun 7 21:07 java -> /etc/alternatives/java
Thanks!
You can add in your .bashrc
file:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and it will dynamically change when you update your packages.
Use the following command to find out exact path to which java executable under UNIX / Linux:
$ which java (suppose returns /usr/java/jdk1.5.0_07/bin/java)
And then set path as export JAVA_HOME=/usr/java/jdk1.5.0_07/bin/java
Best solution tested with Fedora 26 :
echo "JAVA_HOME=/etc/alternatives/jre" >> ~/.profile
source ~/.profile
echo $JAVA_HOME
来源:https://stackoverflow.com/questions/24102816/fedora-openjdk-set-java-home