# How to set heap size via environment variable ES\_JAVA\_OPTS?

**URL:** <https://discuss.elastic.co/t/how-to-set-heap-size-via-environment-variable-es-java-opts/161116>\
**Category:** Elasticsearch\
**Created:** [December 17, 2018, 10:25am UTC](https://discuss.elastic.co/t/how-to-set-heap-size-via-environment-variable-es-java-opts/161116 "2018-12-17T10:25:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![li\_jessen2016](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/li_jessen2016/32/38817_2.png) [@li\_jessen2016](https://discuss.elastic.co/u/li_jessen2016)\
**Post date:** [December 17, 2018, 10:25am UTC](https://discuss.elastic.co/t/how-to-set-heap-size-via-environment-variable-es-java-opts/161116/1 "2018-12-17T10:25:02Z")

</div>

I commented xms and xmx in jvm.options, added export ES\_JAVA\_OPTS="-Xms800m -Xmx800m" in ./bash\_profile. And echo $ES\_JAVA\_OPTS returns "-xms800m -Xmx800m".  
But when I restart ES by .bin/elasticsearch, such a heap setting doesn't take effect. Why? How should I set the ES\_JAVA\_OPTS?

It has been solved. It's the issue of .bash\_profile. Even after source .bash\_profile, it can only change the settings of the current console/terminal. But for other console/terminal, including a new one after closing the current console/terminal, you will find the settings unchanged (you can test it by echo ) since it only load the settings from .bash\_profile as the current user log-in.

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [December 17, 2018, 12:12pm UTC](https://discuss.elastic.co/t/how-to-set-heap-size-via-environment-variable-es-java-opts/161116/2 "2018-12-17T12:12:30Z")

</div>

Not sure in what version the jvm.options file is introduced but is definitly 5.x and greater.  
If you are on elasticsearch 5.x or greater why not use that file?

```
more /etc/elasticsearch/jvm.options
## JVM configuration

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms16g
-Xmx16g
```

---

<div class="post-metadata">

**Author:** ![li\_jessen2016](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/li_jessen2016/32/38817_2.png) [@li\_jessen2016](https://discuss.elastic.co/u/li_jessen2016)\
**Post date:** [December 18, 2018, 12:56am UTC](https://discuss.elastic.co/t/how-to-set-heap-size-via-environment-variable-es-java-opts/161116/3 "2018-12-18T00:56:37Z")

</div>

It is said in the Elasticsearch Reference 6.5 ([https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html)) that " It is also possible to set the heap size via an environment variable. This can be done by commenting out the `Xms` and `Xmx` settings in the [`jvm.options`] file and setting these values via `ES_JAVA_OPTS` :

ES\_JAVA\_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch  
ES\_JAVA\_OPTS="-Xms4000m -Xmx4000m" ./bin/elasticsearch .  
I just want to know how to set the ES\_JAVA\_OPTS environment variable.

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [December 18, 2018, 1:17am UTC](https://discuss.elastic.co/t/how-to-set-heap-size-via-environment-variable-es-java-opts/161116/4 "2018-12-18T01:17:34Z")

</div>

Ok, and that is not working? Not really sure what the issue is here.

---

<div class="post-metadata">

**Author:** ![li\_jessen2016](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/li_jessen2016/32/38817_2.png) [@li\_jessen2016](https://discuss.elastic.co/u/li_jessen2016)\
**Post date:** [December 18, 2018, 1:40am UTC](https://discuss.elastic.co/t/how-to-set-heap-size-via-environment-variable-es-java-opts/161116/5 "2018-12-18T01:40:45Z")

</div>

I tried it again. Just added "ES\_JAVA\_OPTS=-Xms1g -Xmx1g" in .bash\_profile, it works. The issue was the property of .bash\_file, it only works for the current console/terminal, but not for other consoles/terminals unless you restart Linux.

---

<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:** [January 15, 2019, 1:40am UTC](https://discuss.elastic.co/t/how-to-set-heap-size-via-environment-variable-es-java-opts/161116/6 "2019-01-15T01:40:48Z")

</div>

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