'JAVA_HOME file is not working and I couldn't update Java to 1.8 on Amazon EC2

I have an Amazon EC2 t3.medium instance on Linux. I am trying to run Apache ni-fi on this instance and I need java. When I check the JAVA_HOME default:

$ echo$JAVA_HOME

 -bash: echo/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.amzn2.0.2.x86_64: No such file or directory

Then, I downloaded java 1.8 by the following comamnds on terminal:

$ sudo yum install java-1.8.0-openjdk.x86_64

$ sudo update-alternatives --config java

(I selected 2 for java 1.8)

To find the location of my java file, I run them:

$ file $(which java)
/usr/bin/java: symbolic link to `/etc/alternatives/java'
$ file /etc/alternatives/java
/etc/alternatives/java: symbolic link to `/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java'
$ file /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java

/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, BuildID[sha1]=1b1c0fd721197a04f9bfc9b0891f1bd83a5f49d5, not stripped

I guess it is working properly. Then, I change JAVA_HOME from 1.7 to 1.8 by writing these commands on terminal for both ec2-user and root:

[root@ip-178-32-11-247 ~]# export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64"
[root@ip-178-32-11-247 ~]# PATH=$JAVA_HOME/bin:$PATH

In advance, I have setup nifi on root. And in nifi-1.16.0 directory, I am trying to run this command:

[root@ip-178-32-11-247 nifi-1.16.0]# bin/nifi.sh start

The Error message is:

Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64
NiFi home: /root/nifi-1.16.0

Bootstrap Config File: /root/nifi-1.16.0/conf/bootstrap.conf

bin/nifi.sh: line 401: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/bin/java: No such file or directory

I thought that java is working but JAVA_HOME couldn't setup properly but I couldn't solve that. What should I do at that point to solve the problem and start nifi?

I will be appreciated very much if you can help, I coludn't start my term project because of this error :(



Solution 1:[1]

The correct path for JAVA_HOME should be /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java

export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java"

But probably you don't need to export JAVA_HOME anyway. You should have a link in /usr/bin/. You can check this by doing the following:

[ssm-user@ip-172-31-85-243 bin]$ which java
/usr/bin/java

By default Apache Nifi is using the executable /usr/bin/java, so you don't need to export JAVA_HOME.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ervin Szilagyi