booting elasticsearch on machine with 2GB RAM
You should set Xms and Xmx in the jvm.options file. (/etc/elasticsearch/jvm.options)
You can also use environment variables (ES_JAVA_OPTS="-Xms1g -Xmx1g"
), but you need to comment out the settings in jvm.options for that to work.
PS: Assuming 5.x since you didn't specify the version.