Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA not in path although JAVA_HOME set

I have set all the requirement variables in the /etc/profile but when launching elasticsearch, it is still not find Java. How i can set the environment variable. That's my /etc/profile

PATH=$PATH:$HOME/bin
APPLICATIONS=$HOME/Applications
JAVA_HOME=$APPLICATIONS/jdk1.7.0_79
PATH=$JAVA_HOME/bin:$PATH

export APPLICATIONS
export JAVA_HOME
export PATH

Output of commands

[root@87500e63467f Applications]# echo $PATH
/root/Applications/jdk1.7.0_79/bin:/root/Applications/jdk1.7.0_79/bin:/root/Applications/jdk1.7.0_79/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin:/root/bin
[root@87500e63467f Applications]# echo $JAVA_HOME
/root/Applications/jdk1.7.0_79
[root@87500e63467f Applications]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
error: "Read-only file system" setting key "vm.max_map_count"
Starting elasticsearch: which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)
Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME
                                                           [FAILED]

in the error, it says that ""Starting elasticsearch: which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)"", it means really java isn't in that path, but how come when I echo $PATH, it shows that the java is in the path ?

like image 308
Noor Avatar asked Oct 30 '15 15:10

Noor


People also ask

Why JAVA_HOME is not working?

Verify JAVA_HOME Enter the command echo %JAVA_HOME% . This should output the path to your Java installation folder. If it doesn't, your JAVA_HOME variable was not set correctly. Please make sure you're using the correct Java installation folder, or repeat the steps above.

How do you fix please set the JAVA_HOME variable in your environment to match the location of your Java installation?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.

What is difference between JAVA_HOME and path?

PATH values: notice how the directory we set for JAVA_HOME is the JDK installation root whereas for PATH we add the bin directory within the JDK installation. Take care to set these up correctly otherwise you'll have problems later on.


4 Answers

After reading the docs from ElasticSearch, I found that if you're running on Ubuntu or Debian, the package only ships with the OpenJDK because of licensing issues. To fix this Java path problem, I installed the following after installing ElasticSearch (as directed by the docs):

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
java -version

Then upon running sudo service elasticsearch start everything worked and I had no more Java path issues.

like image 195
bkunzi01 Avatar answered Oct 14 '22 03:10

bkunzi01


run the command

java -XshowSettings

search the entry java.home = /usr/java/jdk1.8.0_91/jre

export the java_home in your bash profile

export JAVA_HOME=/usr/java/jdk1.8.0_91/jre

or in /etc/profile to expand to all users

like image 33
Miso Mijatovic Avatar answered Oct 14 '22 03:10

Miso Mijatovic


Specifically for OpenBSD6.0, add

export JAVA_HOME=/usr/local/jdk-1.8.0/

to your .profile.

This specific version of the jdk, and possibly the basic path itself is subject to change in subsequent and previous versions of OpenBSD, you have been warned.

like image 6
danno Avatar answered Oct 14 '22 01:10

danno


To get it going - though not nice - you could setup a symbolic link to your java in /usr/bin (which is listed by elasticsearch to be seen):

ln -s /root/Applications/jdk1.7.0_79/bin/java /usr/bin/java
like image 3
yasd Avatar answered Oct 14 '22 03:10

yasd