(Last Updated On: November 19, 2018)

Elasticsearch is a highly scalable open-source analytics engine and full-text search. With Elasticsearch, you can store, search, and analyze big volumes of data faster and in near real time. Elasticsearch is generally used as the underlying engine/technology that powers applications that have complex search features and requirements.

For Elastisearch 6.x, check How to Install Elasticsearch 6.x on Ubuntu 18.04 LTS (Bionic Beaver) Linux

Here is the guide to install Elasticsearch 5.x on Ubuntu 18.04 LTS.

Step 1: Import Elasticsearch GPG Key

The first step is to import Elasticsearch GPG Key using the command:

$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
OK

Step 2: Add Elasticsearch 5.x APT repository

Once the GPG key has been imported, add the apt repository so that you can install Elasticsearch package from:

$ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list

For Elasticsearch 6.x, add repo below:

echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list

Step 3: Install OpenJDK

Elasticsearch is dependent on Java, you need to install OpenJDK before you can continue.

$ sudo apt update && sudo apt upgrade
$ sudo apt install apt-transport-https uuid-runtime pwgen openjdk-8-jre-headless

Step 4: Update apt package index and Install Elasticsearch 5.x

Now run apt-get update  then install elasticsearch package:

$ sudo apt update
$ sudo apt install elasticsearch

After the installation, a default configuration file will be populated to /etc/elasticsearch/elasticsearch.ymlMost lines are commented out, edit the file to tweak and tune the configuration.

E.g, you can set correct cluster name for your applications:

cluster.name: my-application

Note that the default minimum memory set for JVM is 2gb, if your server has small memory size, change this value:

$ sudo vim /etc/elasticsearch/jvm.options

Change:

-Xms2g
-Xmx2g

And set your values for minimum and maximum memory allocation. E.g to set values to 512mb of ram, use:

-Xms512m
-Xmx512m

After you have modified the configuration, you can start Elasticsearch:

$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch.service
$ sudo systemctl restart elasticsearch.service

Check status:

$ sudo systemctl status elasticsearch.service 
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2018-07-01 10:39:54 UTC; 18s ago
Docs: http://www.elastic.co
Process: 14314 ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec (code=exited, status=0/SUCCESS)
Main PID: 14325 (java)
Tasks: 38 (limit: 2362)
CGroup: /system.slice/elasticsearch.service
└─14325 /usr/bin/java -Xms512m -Xmx512m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -X

That’s all for the installation of Elasticsearch 5.x on Ubuntu 18.04 LTS (Bionic Beaver) Linux.

Elasticsearch Cluster Setup: How to Deploy a three-node Elasticsearch Cluster on Ubuntu 18.04