How to Install and Configure Elasticsearch 9.x on Ubuntu & Debian
Elasticsearch is a powerful, open-source search and analytics engine. While incredibly robust, the initial installation on a Debian-based system like Ubuntu requires a few specific configuration steps to get a single node up and running.This guide will walk you through the entire process, from adding the repository to configuring your node for a development environment.
1. 🔑 Add the Elastic GPG Key
First, you must add the Elastic GPG key to your system. This allowsapt to verify the authenticity of the packages you're about to download, ensuring they haven't been tampered with.
Bash:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
2. 📦 Add the Elasticsearch APT Repository
With the key in place, you now need to tell your system where to find the Elasticsearch packages. We will add the official Elastic repository for version 9.x.This command creates a new source list file for
apt:
Bash:
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/9.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-9.x.list
3. 💻 Install Elasticsearch
Now you are ready to install. Update your package lists to include the new repository, and then install theelasticsearch package itself.
Bash:
sudo apt-get -y update && sudo apt-get -y install elasticsearch
4. 📝 Configure the Elasticsearch Node
This is the most critical step. We need to edit the main configuration file to tell Elasticsearch to run as a single node and to disable security features (for development/testing only).Open the configuration file:
Bash:
sudo nano /etc/elasticsearch/elasticsearch.yml
Now, find and modify the following lines. You will need to uncomment (remove the
#) some of them.
YAML:
# 1. Bind to localhost
# This is crucial for a single-node setup on a machine not exposed to the public.
network.host: localhost
# 2. Disable security (FOR DEVELOPMENT ONLY)
# WARNING: This disables all authentication and encryption.
# Do NOT use this configuration in a production environment.
xpack.security.enabled: false
xpack.security.http.ssl: false
xpack.security.transport.ssl: false
# 3. Set the initial master node
# For a single-node cluster, you must comment out this line
# to bypass the cluster bootstrap checks.
# cluster.initial_master_nodes: ["node-1", "node-2"]
5. 🚀 Adjust the JVM Heap Size (Optional but Recommended)
By default, Elasticsearch's Java Virtual Machine (JVM) heap size can be small. For any real use, you'll want to increase it. The recommended practice is to create a custom override file.- Navigate to the
jvm.options.ddirectory. This is the correct place for custom settings:
Bash:cd /etc/elasticsearch/jvm.options.d/ - Create a new file to set your custom heap size. We'll call it
jvm.options:
Bash:sudo nano jvm.options - Add your minimum (
-Xms) and maximum (-Xmx) heap settings. Using4g(minimum) and6g(maximum) as an example:
Pro-Tip: For production servers, it's best practice to set the minimum and maximum heap size to the same value (e.g.,Bash:-Xms4g -Xmx6g-Xms4gand-Xmx4g) to prevent performance issues from heap resizing.
6. ✅ Start and Enable the Elasticsearch Service
Now that all configurations are in place, you can start the service.- Reload the
systemdmanager to pick up any changes:
Bash:sudo systemctl daemon-reload - Enable the service to start automatically on boot:
Bash:sudo systemctl enable elasticsearch.service - Start the service:
Bash:sudo systemctl start elasticsearch.service
7. 🔎 Verify the Installation
Wait about 30 seconds for the service to initialize, and then check its status:
Bash:
sudo systemctl status elasticsearch.service
If everything is correct, you should see an
active (running) status.You can also test the node by sending a request to it:
Bash:
curl -X GET "localhost:9200"
Last edited: