JDK has been installed in linux, but the JAVA_HOME path cannot be found, and an error is reported when elasticsearch starts. Please set the JAVA_HOME variable in your environment

Brief description of the problem

In centos6.9, the previous OpenJDK was deleted and Oracle's jdk1.8 was replaced, and java -verison was entered to display the version information, but an error was reported when running elasticsearch. Please set the JAVA_HOME variable in your environment and the jdk path was not found.

Solutions

It shows that there is a problem with the jdk installation and configuration. The java-version may not prove that the jdk installation is successful, or when configuring the environment , some tutorials on the Internet create a new file to configure the java environment, but when some components are running and loading, they only view the self-installed files in the linux system. The file with it, so java_path cannot be found. Here, I will give the most comprehensive and correct jdk installation and configuration tutorial .

Operating procedures

1. Uninstall the OpenJDK and related java files that come with the system

Enter java-verison
to see the OpenJDK version information that comes with the system.
insert image description hereType in the command window: rpm -qa | grep java
command description:
rpm management suite
-qa Use query mode to query all suites
grep Find qualified string
java in the file Find files containing java string
insert image description here
In the above files:
the following One can delete
java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64 java
-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
java-1.8.0-openjdk-headless -1.8.0.102-4.b14.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
noarch file can not be deleted
python-javapackages-3.4.1-11.el7. noarch
tzdata-java-2016g-2.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
Type in the command window:
sudo rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6 .7.8.el7.x86_64
For the complete command to delete files , type in the command window:

rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8 .el7.x86_64
command introduction:
rpm management suite
-e deletes the specified suite
–nodeps does not verify the interrelationship of the suite files

Check whether it has been deleted successfully.
Type in the command window: java -version
insert image description here
means that it has been deleted successfully.
If not deleted, use yum -y remove to delete them

2. Install jdk

Because the jdk1.8 resource is a bit old, downloading with wget may invalidate the download address, so use the put command to upload locally , and then tar command to decompress .

After the decompression is complete, name it jdk1.8 (the name is actually random) and put it in /usr/local/jdk (the location is actually random, but you have to remember where you put it)

The following is the most important! ! ! look carefully

Configure the environment variable input:
sudo vim /etc/profile
  
to see the content of this file, the profile file is somewhat similar to the configuration of environment variables in the windows system, as shown in the figure below
insert image description here

shift + g to locate the last line, press the a or i key at this time, enter the edit mode and enter the four-line export content like me (of course, write the address as your own address )

[Note]: CentOS6 is JAVA_HOME, CentOS7 is {JAVA_HOME},
then enter the following four lines of code in the text box, write a line and press Enter
export JAVA_HOME=/usr/local/jdk7
export PATH= JAVAHOME / bin : JAVA_HOME/ bin:JAVAHOMR / bin:PATH
export CLASSPATH=.: J A V A H O M E / l i b / d t . j a r : JAVA_HOME/lib/dt.jar: JAVAHOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
export JRE_HOME=$JAVA_HOME/jre

Exit the file and save it : Press the Esc key and enter: wq to save and exit
to make the configuration file take effect : source /etc/profile
to check whether the configuration is successful : java -version
insert image description here
If the jdk version number appears, the environment variable is installed and configured successfully . If not, check whether the jdk configuration path is wrong.

reboot! Be sure to restart! ! reboot

After the completion, if you want to reboot, you must restart , otherwise some components still cannot recognize jdk, and then I reinstalled it many times like this,,, pit

I think it's good, pay attention to mutual fans, and leave a message in the comment area if you have any questions

Guess you like

Origin blog.csdn.net/weixin_43419816/article/details/127511037