In this article we are going to see how to install ElasticSearch as service on Ubuntu 18.04.


Verify Java is installed:

$ java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing)

Also verify the environment variable JAVA_HOME is set.


If the previous command return an empty string you need to set the environment variable in your ~/.zshrc. Add this line: export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64.

Please note that it might not be this path /usr/lib/jvm/java-11-openjdk-amd64 in your case. Just check what java path you have under /usr/lib/jvm.

Install Elasticsearch

sudo apt-get install apt-transport-https
# Add gpg key
wget -qO - | sudo apt-key add -
# Add ES repo
add-apt-repository "deb stable main"
sudo apt-get update
# Install ES
sudo apt-get install elasticsearch

Add Servicce

sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
# To debug
sudo systemctl status elasticsearch.service
# or 
journalctl -xe

Verify it is working

curl -X GET http://localhost:9200

To customize ES settings you can edit the well documented configuration file located in this path /etc/elasticsearch/elasticsearch.yml.