How to Install Elasticsearch on Ubuntu 20.04/18.04/16.04 LTS

In this article, We are going to perform, How to Install Elasticsearch on Ubuntu 20.04/18.04/16.04 LTS or any Cloud Instance like Amazon EC2, Azure VM, Google Compute Engine,etc. with preinstalled


Elasticsearch is a free and open source search and analytics engine. It is used to store, search and analyze big volumes of data quickly and real time.


  • Ubuntu Server with 20.04/18.04/16.04 LTS
  • Java 8 or higher version
  • 2 CPU and 4 GB RAM
  • Open Ports 9200

Update the system packages

$ sudo apt update

Install the apt-transport-https package to access repository over HTTPS

$ sudo apt install apt-transport-https

Install Java on Ubuntu

Lets install OpenJDK 11 on ubuntu  using below commands.

$ sudo apt install openjdk-11-jdk

Lets verify java version

$ java -version


openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Set Default Java Version using update alternatives

If you have installed multiple Java versions on your system and you want to set Default Java version on Ubuntu. Lets set Default Java Version using update alternatives command,

$ sudo update-alternatives --config java

It prompts for selecting by 0,1, choose accordingly:

Setting the JAVA_HOME Environment Variables

To define the environment variable open the below file:
$ sudo nano /etc/environment
Paste the below variable into the file:

For OpenJDK 8 java is installed at /usr/lib/jvm/java-11-openjdk-amd64/bin/java location


Load the environment variable using below command

$ source /etc/environment

Lets verify JAVA_HOME variable

$ echo $JAVA_HOME



Step 1: Install ElasticSearch on Ubuntu

Here, We are adding ElasticSearch official apt package and this is signed with GPG keys

$ sudo wget -qO - | sudo apt-key add -

Next add the repository in /etc/apt/sources.list.d/elastic-7.x.list using below command.

$ sudo echo "deb stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

To install elasticsearch enter below command

$ sudo apt-get update
$ sudo apt-get install elasticsearch

Start elacticsearch services

$ sudo systemctl start elasticsearch

Enable elacticsearch at system startup

$ sudo systemctl enable elasticsearch

To check the status of elasticsearch

$ sudo systemctl status elasticsearch


elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-05-28 05:31:52 UTC; 1 day 3h ago
Main PID: 156620 (java)
Tasks: 68 (limit: 19185)
Memory: 1.3G
CGroup: /system.slice/elasticsearch.service
├─156620 /usr/share/elasticsearch/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xs>
└─156730 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Step 2: Configure Elasticsearch

Let’s make changes in below configuration file

$ sudo nano /etc/elasticsearch/elasticsearch.yml

Go to Network section and uncommnet and replace your system IP or localhost
# ---------------------------------- Network -----------------------------------
# Set the bind address to a specific IP (IPv4 or IPv6):
# Set a custom port for HTTP:
#http.port: 9200
# For more information, consult the network module documentation.

Restart elacticsearch services to take effect

$ sudo systemctl restart elasticsearch

Here We have covered How to Install Elasticsearch on Ubuntu

Step 3: Add Firewall Rule

To allow traffic on port 9200 enter the below command:

$ sudo ufw allow 9200/tcp

Step 4: Testing Elasticsearch

Lets test Elasticsearch using curl command by sending HTTP request

$ curl -X GET "localhost:9200"


  "name" : "ip-192-168-100-10",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "ciPfyPlvT1K7lVmOv_Jbtw",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  "tagline" : "You Know, for Search"


You can access using browser


Error: ElasticSearch 7 start up error – the default discovery settings are unsuitable for production use;

ERROR: Elasticsearch did not exit normally – check the logs at /var/log/elasticsearch/elasticsearch.log

If you have installed Elasticsearch on Single system and you are unable start Elasticsearch service due to above error.

Open Elasticsearch configuration , navigate to Discovery section and change below as shown below

# --------------------------------- Discovery ----------------------------------
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["", "[::1]"]
discovery.seed_hosts: [ ]
# Bootstrap the cluster using an initial set of master-eligible nodes:
#cluster.initial_master_nodes: ["node-1", "node-2"]
# For more information, consult the discovery and cluster formation module documentation.


In this article, We have performed ,How to Install Elasticsearch on Ubuntu, Configure Elasticsearch, Testing and Adding firewall rule.

Related Articles:

How to Install ELK Stack on Ubuntu 18.04/16.04 LTS

How to Install Elastic Stack on CentOS 7


Elasticsearch Official Guide

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link