How to install Elasticsearch on Ubuntu 20.04

Elasticsearch is an open source, distributed, full-text search and analysis engine. It supports RESTful operations and allows you to store, search and analyze large amounts of data in real time. Elasticsearch is one of the most popular search engines for applications that have complex search requirements such as large e-commerce stores and analytics applications.

This article explains how to install Elasticsearch on Ubuntu 20.04.

Installing Elasticsearch

Installing Elasticsearch on Ubuntu is pretty straightforward. We’ll enable Docker repository, import the repository GPG key, and install Elasticsearch.

The Elasticsearch package comes bundled with the OpenJDK version, so you don’t need to install Java.

First, update the package index and install the dependencies required to add the new HTTPS repository:

sudo apt update
sudo apt install apt-transport-https ca-certificates wget

Import the repository GPG key:

wget -qO - | sudo apt-key add -

The command above should output OK, which means that the key was imported successfully and packages from this repository will be considered trusted.

Then add the Elasticsearch repository to the system by running:

sudo sh -c 'echo "deb stable main" > /etc/apt/sources.list.d/elastic-7.x.list'

If you want to install a previous version of Elasticsearch, change 7.x in the above command to the version you want.

Once the repository is enabled, install Elasticsearch by typing:

sudo apt update
sudo apt install elasticsearch

The Elasticsearch service will not start automatically after the installation process completes. To start the service and enable it, follow these steps.

sudo systemctl enable --now elasticsearch.service

To make sure Elasticsearch is running, use curl to send an HTTP request on port 9200 on localhost:

curl -X GET "localhost:9200/"

You should see something similar to this:

  "name" : "vagrant",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "IJqDxPfXSrmFQ27KbXbRIg",
  "version" : {
    "number" : "7.8.0",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65",
    "build_date" : "2020-06-14T19:35:50.234439Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  "tagline" : "You Know, for Search"

It may take 5-10 seconds for the service to start. If you see curl: (7) Failed to connect to localhost port 9200: Connection refused, wait a few seconds and try again.

To view messages logged by the Elasticsearch service, use the following command:

sudo journalctl -u elasticsearch

That’s all. Elasticsearch has been installed on your Ubuntu server.

Elasticsearch setup

Elasticsearch data is stored in the / var / lib / elasticsearch directory. The configuration files are located in the files / etc / elasticsearch, / etc / default / elasticsearch, and in the file you can configure the Java startup parameters.

By default, Elasticsearch is configured to listen on localhost only. If the client connecting to the database is also running on the same host and you are setting up a single node cluster, you do not need to modify the default configuration file.

Remote access

Out of the box, Elasticsearch does not implement authentication, so anyone who has access to the HTTP API can access it.

To allow remote access to the Elasticsearch server, you need to configure your firewall and open TCP port 6379.

Typically, you want to only allow access to the Redis server from a specific IP address or range of IP addresses. For example, to only allow connections from the subnet, you would run the following command:

sudo ufw allow proto tcp from to any port 6379

After configuring the firewall, the next step is to edit the Elasticsearch configuration and allow Elasticsearch to listen on external connections.

To do this, open the elasticsearch.yml configuration file:

sudo nano /etc/elasticsearch/elasticsearch.yml

Find the line it contains, uncomment it and change the value to


If you have multiple network interfaces on your computer, specify the IP address of the interface so that Elasticsearch will only listen on this interface.

Restart the Elasticsearch service for the changes to take effect:

sudo systemctl restart elasticsearch

That’s all. You can now connect to the Elasticsearch server from your remote location.


We showed you how to install Elasticsearch on Ubuntu 20.04.

If you run into an issue or have feedback, please leave a comment below.