How to Install Elasticsearch on Ubuntu 22.04

Install ElasticSearch on Ubuntu 22.04

In this tutorial, we are going to show you how to install and configure Elasticsearch on Ubuntu 22.04

Elasticsearch is a search engine based on the Lucene library. It is distributed, scalable, and open-source software used to store the collected data. On a daily basis, the administrators use elasticsearch because it has many features such as high availability, various sets of APIs, support for more than one index, native Java API, and many more.

Installing Elasticsearch on Ubuntu 22.04 is a straightforward process that can take up to 15 minutes. Let’s get started!


  • Fresh install of Ubuntu 22.04
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

If you have a fresh installation of Ubuntu 22.04, then it is recommended to update the system packages to their latest versions available.

sudo apt update -y && sudo apt upgrade -y

Step 2. Install Elasticsearch

First, we are going to add the elasticsearch public key to the APT and the elastic source to the sources.list.d. This is necessary because there are no available Elasticsearch components in the default Ubuntu 22.04 repository.

To add the GPG-KEY execute the following command:

curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg

To add the elastic source to the sources.list.d, execute the following command:

echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

After adding them, your command line should look like this.

root@host:~# curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg
root@host:~# echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
deb [signed-by=/usr/share/keyrings/elastic.gpg] stable main

Now, update the system and install the elastic search with the following commands:

sudo apt update -y

sudo apt install elasticsearch

Once the installation is completed, start and enable the elasticsearch service.

sudo systemctl start elasticsearch && sudo systemctl enable elasticsearch

After starting and enabling the service, you should receive the following output:

Synchronizing state of elasticsearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable elasticsearch
Created symlink /etc/systemd/system/ → /lib/systemd/system/elasticsearch.service.

To check the status of the service, if it is up and running, execute the following command:

sudo systemctl status elasticsearch

You should receive the following output:

root@host:~# sudo systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
     Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-09-20 18:59:08 CEST; 2min 6s ago
   Main PID: 115284 (java)
      Tasks: 70 (limit: 4575)
     Memory: 2.3G
        CPU: 1min 42.632s
     CGroup: /system.slice/elasticsearch.service
             ├─115284 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch>
             └─115476 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Sep 20 18:58:26 host.test.vps systemd[1]: Starting Elasticsearch...
Sep 20 18:59:08 host.test.vps systemd[1]: Started Elasticsearch.

Step 3. Configure Elasticsearch

The fresh installation of Elasticsearch without configuration is not enough for elasticsearch to run the way it should. Well, it will run properly, but it is recommended to reconfigure some of the original settings.

The main configuration file of Elasticsearch is located at /etc/elasticsearch/elasticsearch.yml on the server. Before we make any changes, it is recommended to have a copy of the original file.

cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.original

Now, when we have a copy, we can proceed with configuring the Elasticsearch service.

The Elastic search service listens on port 9200 from everywhere only on the loopback interface

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer

Now just $43 .99

root@host:~# netstat -tunlp | grep 9200
tcp6       0      0          :::*                    LISTEN      115284/java
tcp6       0      0 ::1:9200                :::*                    LISTEN      115284/java

To restrict access from everywhere, open the elasticsearch.yml and find the line and set the to localhost.

# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
# localhost
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:

Next is to allow access to the default Elasticsearch HTTP API port for the trusted remote host via a specific IP address. That IP address is the IP address of the server. Access will be allowed with the UFW service.

sudo ufw allow from your_server_ip_address to any port 9200

These are the basic steps to configure and secure Elasticsearch. If you want, you can change the listening port 9200 to another, but you will have to repeat these steps again. It is up to you.

The last thing is to test Elasticsearch. To do that, just execute the curl -X GET ‘http://localhost:9200’ command in your command line. You should receive the following output:

root@host:~# curl -X GET 'http://localhost:9200'
  "name" : "host.test.vps",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "4fzCc1XzQjOwpHqJgWBNvg",
  "version" : {
    "number" : "7.17.6",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "f65e9d338dc1d07b642e14a27f338990148ee5b6",
    "build_date" : "2022-08-23T11:08:48.893373482Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  "tagline" : "You Know, for Search"

Congratulations! You successfully installed and configured Elasticsearch on Ubuntu 22.04 in no time.

Of course, if this setup is complex for you, you just need to sign up for one of our NVMe VPS plans and submit a support ticket. Our admins will help you with any aspect of configuring Elasticsearch. We are available 24/7.

If you liked this about installing Elasticsearch on Ubuntu 22.04, please share it with your friends on social networks or simply leave a reply below. Thanks.

Leave a Comment