How to Install and Configure Elasticsearch on Ubuntu 20.04

Elasticsearh is a search and analytics engine. It is distributable and easily scalable, focused primarily on the business and scientific world. It is accessible through an extensive and elaborate API. The main advantage of using Elasticsearch is to get results within a large amount of possible data.

Moreover, it is written in Java and released under the Apache license. We can install the software directly on our favorite GNU/Linux distribution, on Amazon AWS, or Microsoft Windows Azure. That is why it is present on many servers worldwide.

Fast, stable, with a powerful API, and with great support for the best programming languages are the main reasons why even Netflix dares to use Elasticsearch.

Install Elasticsearch on Ubuntu 20.04

As expected, Elasticsearch is not available in the official Ubuntu 20.04 repositories but it is quite easy to install.

1. Install Java on Ubuntu 20.04

As Elasticsearch is built in Java, what we need to do is to install it as a dependency. To do this, open a terminal or connect via SSH and update Ubuntu.

sudo apt update
sudo apt upgrade

After the system is fully upgraded, it is possible to install Java by running:

sudo apt install openjdk-11-jre

After that, we can start the installation.

2. Installing Elasticsearch on Ubuntu 20.04

As Elasticsearch is not included in the official repositories of Ubuntu 20.04 we have to look for other ways to install it. The recommended method is to add the official repository of the application for Ubuntu 20.04.

First, add the GPG key to the repository so that the system can confidently install applications from there.

curl -fsSL | sudo apt-key add -

Sample Output:


Now add the repository with the following command:

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

Now refresh APT by running

sudo apt update

Finally, it’s time to install Elasticsearch by running it:

sudo apt install elasticsearch

When the installation is finished you will be able to manage it as a system service and the command systemctl

sudo systemctl enable elasticsearch --now
sudo systemctl status elasticsearch

This will get it working properly.

Configure Elasticsearch on Ubuntu 20.04

All the Elasticsearch configuration is in the elasticsearch.yml file where we can make many different settings.

Before editing it, it is a good idea to make a backup.

sudo cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.bak

And then edit it:

sudo nano /etc/elasticsearch/elasticsearch.yml

The file is in YML format so be careful when editing it. In this file, we can configure the name of the cluster, the port where Elasticsearch will run, as well as the IP address where it will work.

In our case, just modify the value that refers to the server where Elasticsearch is running. As it will work locally, just add/change localhost

Save the changes, close the editor and apply the changes by restarting the service.

systemctl restart elasticsearch

Testing Elasticsearch

To enjoy the full potential of Elasticsearch it is necessary to create a productive environment but we can test locally if the installation has worked.

To do this, just run the following command:

curl -X GET 'http://localhost:9200'

Sample Output:

"name" : "imaginelinux",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "2n4EAxqYQPGNSL4Pg96_-A",
"version" : {
"number" : "7.11.1",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "ff17057114c2199c9c1bbecc727003a907c0db7a",
"build_date" : "2021-02-15T13:44:09.394032Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
"tagline" : "You Know, for Search"

When you get an output similar to the one shown, then you know that Elasticsearch has been successfully installed.

Removing Elasticsearch

To uninstall Elasticsearch is also quite simple because to do so, you need to run

sudo apt remove elasticsearch

But it is also convenient to remove the repository we have added to avoid problems.

sudo rm /etc/apt/sources.list.d/elastic-7.x.list

This way there will be no trace of Elasticsearch left.


Every day OpenSource applications become more and more important and functional. That’s why Elasticsearch has earned its place in today’s technology scene. Therefore, as a user and programmer, you should learn how to install Elasticsearch on Ubuntu 20.04, although this is really easy and within the reach of many.

Tell us, did you know about Elasticsearch? what do you think about it? let us know in the comments and share the post.

Scroll to Top