# How can I modify the path Elasticsearch 2.4.6 uses to run Java in Linux?

**URL:** <https://discuss.elastic.co/t/how-can-i-modify-the-path-elasticsearch-2-4-6-uses-to-run-java-in-linux/335893>\
**Category:** Elasticsearch\
**Created:** [June 13, 2023, 4:18pm UTC](https://discuss.elastic.co/t/how-can-i-modify-the-path-elasticsearch-2-4-6-uses-to-run-java-in-linux/335893 "2023-06-13T16:18:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Latitude](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Latitude](https://discuss.elastic.co/u/Latitude)\
**Post date:** [June 13, 2023, 4:18pm UTC](https://discuss.elastic.co/t/how-can-i-modify-the-path-elasticsearch-2-4-6-uses-to-run-java-in-linux/335893/1 "2023-06-13T16:18:32Z")

</div>

Brand new to Elasticsearch. Can anyone explain how how to modify the path Elasticsearch v2.4.6 uses for Java on Linux? There is a discrepancy between Test and Production and I need to change Test to match Production:

Production Server:

```auto
elastic+ 1265 1 3 2022 ? 5-19:32:36 /bin/java

/bin/java -> /etc/alternatives/java

/etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/ **jre/bin/java**

```

Test Server:

```auto
elastic+ 1243 1 0 2022 ? 22:00:51 /usr/lib/jvm/java-oracle/bin/java

/usr/lib/jvm/java-oracle -> /etc/alternatives/java_sdk_oracle

/etc/alternatives/java_sdk_oracle -> /usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64

/usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/ **bin/java**

```

I need to modify the Test server to use the same Java binary as Production Server which is obscured a little bit by several soft (symbolic links) but the slightly different absolute paths are above. How can I modify the path Elasticsearch uses to run Java? Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 13, 2023, 4:18pm UTC](https://discuss.elastic.co/t/how-can-i-modify-the-path-elasticsearch-2-4-6-uses-to-run-java-in-linux/335893/2 "2023-06-13T16:18:32Z")

</div>

Elasticsearch 2.4.6 is [EOL](https://www.elastic.co/support/eol) and no longer supported. Please upgrade ASAP.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<div class="post-metadata">

**Author:** ![Latitude](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Latitude](https://discuss.elastic.co/u/Latitude)\
**Post date:** [June 13, 2023, 5:49pm UTC](https://discuss.elastic.co/t/how-can-i-modify-the-path-elasticsearch-2-4-6-uses-to-run-java-in-linux/335893/3 "2023-06-13T17:49:39Z")

</div>

Just so everyone knows, yes, I'm aware Elasticsearch 2.4.6 is EOL and we are still a few months away from testing and cutting over to new Test and Production servers running Liferay 7.4 DXP with Elasticsearch 7.17.9, however our web developers are troubleshooting an issue with the frontend web site with the root cause suspected to be the path to the Java binary that still needs to be modified to match Production, so if anyone can comment how to do this I'd appreciate the help.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 13, 2023, 11:26pm UTC](https://discuss.elastic.co/t/how-can-i-modify-the-path-elasticsearch-2-4-6-uses-to-run-java-in-linux/335893/4 "2023-06-13T23:26:06Z")

</div>

You can define what JVM Elasticsearch uses as per [Setup | Elasticsearch Guide [2.4] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.4/setup.html#jvm-version);

> The version of Java to use can be configured by setting the `JAVA_HOME` environment variable.

This may also be more of an OS specific question, but [debian - How to use the command update-alternatives --config java - Stack Overflow](https://stackoverflow.com/questions/12787757/how-to-use-the-command-update-alternatives-config-java) has some options.

---

<div class="post-metadata">

**Author:** ![Latitude](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Latitude](https://discuss.elastic.co/u/Latitude)\
**Post date:** [June 16, 2023, 7:59pm UTC](https://discuss.elastic.co/t/how-can-i-modify-the-path-elasticsearch-2-4-6-uses-to-run-java-in-linux/335893/5 "2023-06-16T19:59:31Z")

</div>

Thanks, I really needed to know more specifically how can I set the JAVA\_HOME variable. I eventually looked at the file /usr/share/elasticsearch/bin/elasticsearch

Through quite a bit of searching I found an include file /usr/share/elasticsearch/bin/elasticsearch and it contained the following code block which indicated I was close to finding it:

```auto
if [-x "$JAVA_HOME/bin/java"]; then
    JAVA="$JAVA_HOME/bin/java"
else
    JAVA=`which java`
fi

if [! -x "$JAVA"]; then
    echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
    exit 1
fi

if [-z "$ES_CLASSPATH"]; then
    echo "You must set the ES_CLASSPATH var" >&2
    exit 1
fi

```

At the top of this file under where it says CONTROLLING STARTUP I found several Java variables so I knew I was close to finding the JAVA\_HOME environment variable:

```auto
# ES_CLASSPATH -- A Java classpath containing everything necessary to run.
# JAVA_OPTS -- Additional arguments to the JVM for heap size, etc
# ES_JAVA_OPTS -- External Java Opts on top of the defaults set

```

Further down in the file I saw:

```auto
# Any serious use-case though will likely require customization of the
# include. For production installations, it is recommended that you copy
# the sample to one of /usr/share/elasticsearch/elasticsearch.in.sh,
# /usr/local/share/elasticsearch/elasticsearch.in.sh, or
# /opt/elasticsearch/elasticsearch.in.sh and make your modifications there.

```

I ran ls -al on /usr/share/elasticsearch/bin and saw the file elasticsearch.in.sh and found the entry I needed to fix: JAVA\_HOME=/usr/lib/jvm/java-oracle. I modified it to JAVA\_HOME=/bin/java, saved the file, and restarted both elasticsearch nodes in the cluster.

For some reason the elasticsearch daemon executed /usr/bin/java, but through a series of symolic links, it still executes the Java binary we need at the path we need, **/usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86\_64/jre/bin/java** :

```auto
[root@liferayhost1] ps -ef | grep elastic
elastic+ 96919 1 74 15:04 ? 00:00:15 /usr/bin/java -Xms12g -Xmx12g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/share/elasticsearch -cp /usr/share/elasticsearch/lib/elasticsearch-2.4.6.jar:/usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch start -Des.pidfile=/var/run/elasticsearch/elasticsearch.pid -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/var/log/elasticsearch -Des.default.path.data=/usr/local/liferay/elasticsearch/var -Des.default.path.conf=/etc/elasticsearch
root 97041 91410 0 15:04 pts/43 00:00:00 grep --color=auto elastic
[root@portaltest2 bin] ls -al /usr/bin/java
lrwxrwxrwx. 1 root root 22 Jun 28 2018 /usr/bin/java -> /etc/alternatives/java
[root@portaltest2 bin] ls -al /etc/alternatives/java
lrwxrwxrwx. 1 root root 71 Jun 28 2018 /etc/alternatives/java -> **/usr/lib/jvm/java-1.8.0-oracle-1.8.0.151-1jpp.5.el7.x86_64/jre/bin/java**
[root@portaltest2 bin] ls -al /bin/java
lrwxrwxrwx. 1 root root 22 Jun 28 2018 /bin/java -> /etc/alternatives/java

```

I'm satisfied that we've modified the JAVA\_HOME environment variable in the include file at /usr/share/elasticsearch/bin/elasticsearch.in.sh used by the file /usr/share/elasticsearch/bin/elasticsearch to start Elasticsearch 2.4.6 with Java. Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 14, 2023, 8:00pm UTC](https://discuss.elastic.co/t/how-can-i-modify-the-path-elasticsearch-2-4-6-uses-to-run-java-in-linux/335893/6 "2023-07-14T20:00:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
