How to Install Elasticsearch: A Step-by-Step Tutorial

This easy-to-follow guide will walk you through the complete process of setting up and running Elasticsearch on your server.

gunicorn

Introduction to Modern Data Search

Linux

Understanding What Elasticsearch Is

Elasticsearch is a highly popular, open-source search and analytics engine used by developers around the world. It is built on top of a powerful technology called Apache Lucene. Instead of storing data in traditional tables like a standard database, Elasticsearch stores information in a way that makes searching through massive amounts of text incredibly fast.

At its core, Elasticsearch works by saving data as organized text files called JSON documents. When you add data to it, the engine creates a special map of words called an "inverted index." This index works much like the glossary at the back of a textbook, allowing the system to instantly find which document contains the exact word or data you are looking for.

People use Elasticsearch for many different reasons in the real world. It is the perfect tool if you need to add a fast search bar to your website, monitor computer system logs in real-time, or analyze large sets of business data. Because it is designed to run across multiple computers at once, it can easily handle massive amounts of information without slowing down.

Prerequisites

  • A computer or server running a Debian or Ubuntu Linux operating system.
  • A user account with sudo (administrator) privileges.
  • At least 4GB of memory (RAM) available on your system.
  • Access to your system's command-line terminal.
  • A stable internet connection to download the required files.

Step-by-Step Installation

1

Import the Elasticsearch PGP Key

First, you need to download the official security key so your system knows the files are safe and actually come from Elastic. Run this command:
BASH
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
2

Install APT Transport HTTPS

Next, install a small tool that allows your server to safely download files over a secure web connection (HTTPS):
BASH
sudo apt-get install apt-transport-https -y
3

Add the Elasticsearch Repository

Now, you need to tell your computer exactly where to find the Elasticsearch software. This command adds the official download link to your system:
BASH
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list
4

Install Elasticsearch

Update your system's list of available software, and then install the Elasticsearch program:
Bash
sudo apt-get update
sudo apt-get install elasticsearch -y
Important Note: When this installation finishes, look closely at your terminal screen.
Elasticsearch will automatically create a password for the main elastic user. Copy and save this password immediately, as you will need it later!
5

Start and Enable the Elasticsearch Service

Tell your computer to recognize the new software, set it to start automatically if your computer restarts, and then turn it on:
Bash
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
(Please wait a minute or two after running the last command to give Elasticsearch time to fully start up.)
6

Verify the Installation

To make sure everything is working perfectly, test the connection. Because version 8 has security turned on by default, you need to use the security certificate and the username elastic:
Bash
curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic https://localhost:9200
When it asks for a password, paste the one you saved in Step 4. If you see a code block on your screen with the phrase "You Know, for Search" , your installation was a complete success!

Discover CTCservers Dedicated Server Locations

CTCservers servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.