简体   繁体   中英

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 ?

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.

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

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.

为了实现它 - 虽然不是很好 - 您可以在/ usr / bin中设置一个指向java的符号链接(由elasticsearch列出可以看到):

ln -s /root/Applications/jdk1.7.0_79/bin/java /usr/bin/java

I noticed one file in the output called /etc/sysconfig/elasticsearch

this might do the trick, so I defined JAVA_HOME in this file like, and it works.

more u can get from here

Make sure the path you have provided for JAVA_HOME is correct.

And why not keep it simple:

export PATH=$PATH:/path/to/jdk

try to set Java home to /jdk1.7.0_79/bin and see if that helps.

Simply add the below path in bashrc and profile file under /etc/ directory.

export JAVA_HOME=/path/to/java/jdk

export PATH=$JAVA_HOME/bin:$PATH

Encountered the same issue while installing Elasticsearch 5 on a debian machine. That's how I installed Java 9:

su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java9-installer

I don't know if this is your particular situation, but working with ElasticSearch/Kibana/Logstash (ELK stack) the docs didn't work for me on Ubuntu 16.04. Putting content from this post together with several others, my solution was:

 sudo add-apt-repository ppa:webupd8team/java
 sudo apt-get update
 sudo apt-get install oracle-java8-installer
 # checking my work given 9 won't work with OSSEC you can use
 # java -version
 sudo usermod -a -G ossec logstash
 sudo apt-get install logstash
 sudo systemctl daemon-reload
 sudo systemctl enable logstash.service
 sudo systemctl start logstash.service

The end result for me on ubuntu 16.04 was

sudo java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

If you are working with wazuh, it is important to add the PPAs for their specific versions. I hope this helps.

you need set JAVA_HOME in the /etc/default/elasticsearch,like
cat /etc/default/elasticsearch JAVA_HOME=/var/local/jdk1.8.0_151

the next start /etc/init.d/elasticsearch start
ES running. my OS ubuntu18.04.

If you are using "not installed" Java, check if your "elasticsearch" user has access to the defined by you JAVA_HOME directory and all parent directories. That was my problem..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM