How to Install and Set Up Elasticsearch on Debian 11

how to install and set up elasticsearch on debian 11

Elasticsearch is a distributed, free and open search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured.

Since its initial release in 2010, Elasticsearch, built on Apache Lucene, has become the most popular search engine commonly used for log analytics, full-text search, etc.

In this article, we will show you how to install and set up Elasticsearch on Debian 11.


  • A Debian 11 VPS with at least 4GB of RAM
  • SSH access with sudo privileges or root access.

In addition, it is recommended to have at least 2GB of SWAP memory, even if you have enough available RAM.

Step 1. Update the System

First of all, we need to log in to our Debian 11 VPS through SSH:

ssh root@IP_Address -p Port_number

Replace “root” with a user with sudo privileges or root if necessary. Additionally, replace “IP_Address” and “Port_Number” with your server’s respective IP address and SSH port number. Next, let’s make sure that we’re on Debian 11. You can do that like this:

# lsb_release -a

You should get an output like this one:

Distributor ID: Debian
Description: Debian GNU/Linux 11 (bulleseye)
Release: 11
Codename: bullseye

Then, run the following command to make sure that all installed packages on the server are updated to their latest available versions:

# apt update && apt upgrade

Step 2. Install Dependencies

There are some dependencies you would need to install before proceeding with the next steps.

# apt install gnupg wget apt-transport-https

Step 3. Install Java

To run Elasticsearch, we need Java. Let’s install it from the default Debian 11 repository.

# apt install default-jre

Debian 11 ships with Java 11 by default; it can be verified by running this command below.

# java --version

You will get an output like this:

openjdk 11.0.18 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Debian-1deb11u1, mixed mode, sharing)

Step 4. Add Elasticsearch Repository

To ensure the download source is secure and from the official source, we need to import the GPG key by downloading it using wget.

# wget -qO - | gpg --dearmor | tee /usr/share/keyrings/elasticsearch.gpg

Debian 11 does not ship with a package for Elasticsearch. Fortunately, the Elasticsearch developer team has provided its own repository packages for Debian. We can add the Elasticsearch repository by executing the command below.

# echo "deb [signed-by=/usr/share/keyrings/elasticsearch.gpg] stable main" | tee /etc/apt/sources.list.d/elastic-8.list

To refresh the system packages index and update the list of available packages after adding a new repository, we should run apt update.

# apt update -y

Step 5. Install Elasticsearch

We added the Elasticsearch repository in the previous step, and the package metadata list has also been updated. We can now install Elasticsearch by invoking this command:

# apt install elasticsearch

On the Debian 11 system, once Elasticsearch is installed, it is not automatically running. Execute the following command to run Elasticsearch and enable it on boot.

# systemctl enable --now elasticsearch

That’s it, Elasticsearch is now running, and you can verify with this command

# systemctl status elasticsearch

It will return an output like this:

● elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-04-18 08:59:54 EDT; 1min 14s ago
Main PID: 8236 (java)
Tasks: 71 (limit: 2294)
Memory: 1.3G
CPU: 44.403s
CGroup: /system.slice/elasticsearch.service
├─8236 /usr/share/elasticsearch/jdk/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.script=/usr/share/elasticsearch/bin/elasticsearch -Dcli.libs=lib/tools>
├─8295 /usr/share/elasticsearch/jdk/bin/java -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch ->
└─8315 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller

Apr 18 08:59:13 debian11 systemd[1]: Starting Elasticsearch...
Apr 18 08:59:54 debian11 systemd[1]: Started Elasticsearch.

Step 6. Configure Elasticsearch

There are some configurations you can modify. But, first of all, we will reset the ‘elastic’ user password. To proceed with this, we can disable the cluster if it’s not used.

comment this line “cluster.initial_master_nodes: [“YOURHOSTNAME”]” then add this line: discovery.type: single-node

It should look like this:

#cluster.initial_master_nodes: ["debian11"]
discovery.type: single-node

And restart Elasticsearch

# systemctl restart elasticsearch

Next, let’s reset Elastic’s password.

# /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic

The command above will prompt you that it will print the new password in the console; press Y to continue.

It returns this output:

This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y

After pressing Y, it will print you the new password and save it.

Password for the [elastic] user successfully reset.
New value: taSSapenu32gkAS0098B

With the new password, we can run this command to check its connection to Elasticsearch.

# curl -u "elastic:taSSapenu32gkAS0098B" https://localhost:9200 -k

The command will return an output like this.

"name" : "debian11",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "rByiAU1MTgKUrsYMjX4E4A",
"version" : {
"number" : "8.7.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "09520b59b6bc1057340b55750186466ea715e30e",
"build_date" : "2023-03-27T16:31:09.816451435Z",
"build_snapshot" : false,
"lucene_version" : "9.5.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
"tagline" : "You Know, for Search"

Next, by default, Elasticsearch is only accessible on localhost. We can set a different address to expose the running node on the network by adding this line to the configuration file:

Another important setting is the jvm.options. We can create a file in /etc/elasticsearch/jvm.options.d/ directory. By default, Elasticsearch automatically sets the JVM heap size based on a node’s role and the available, total memory.  Using the default sizing is recommended for most production environments.

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


To override the default heap size, set the minimum and maximum heap size settings, Xms and Xmx. The minimum and maximum values must be the same. Let’s create a file there and configure the minimum and maximum java heap space.

# nano /etc/elasticsearch/jvm.options.d/memory.conf

And paste these two lines in to that file.


Save the file, then exit. Always remember to restart the service every time we make changes to the configuration file.

# systemctl restart elasticsearch

Congratulations! You have successfully installed and configured Elasticsearch on Debian 11.

Of course, if you are one of our Debian Hosting customers, you don’t have to install and set up Elasticsearch on Debian 11 yourself – simply ask our admins, sit back, and relax. Our admins will install and set up Elasticsearch on Debian 11 immediately without any additional fee, along with many useful optimizations we can do for you. Managing an Elasticsearch server is not just about the installation; we can help you optimize your Elasticsearch installation if you have a VPS with us.

If you liked this post about how to install and set up Elasticsearch on Debian 11, please share it with your friends on social networks or simply leave a comment in the comments section. Thanks.

Leave a Comment