---
title: "Install Elasticsearch on Ubuntu for Next Level Searching"
description: "Learn how to install Elasticsearch on Ubuntu and take your search ability to the next level with this flexible and fast search engine!"
canonical: "https://adamtheautomator.com/install-elasticsearch-on-ubuntu/"
---

# Install Elasticsearch on Ubuntu for Next Level Searching

> Learn how to install Elasticsearch on Ubuntu and take your search ability to the next level with this flexible and fast search engine!

Source: https://adamtheautomator.com/install-elasticsearch-on-ubuntu/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Install Elasticsearch on Ubuntu for Next Level Searching](https://adamtheautomator.com/wp-content/uploads/2022/05/Install-Elasticsearch-on-Ubuntu-for-Next-Level-Searching-1.jpg)

# Install Elasticsearch on Ubuntu for Next Level Searching

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)6 May 20228 min. read

Categories: [DevOps](/category/devops/)

Tags:[ElasticSearch](/tag/elasticsearch/)[Ubuntu Linux](/tag/ubuntu-linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing Java on Ubuntu](#installing-java-on-ubuntu)
*   [Install Elasticsearch on Ubuntu](#install-elasticsearch-on-ubuntu)
*   [Configuring Elasticsearch](#configuring-elasticsearch)
*   [Securing Elasticsearch Using UFW Firewall](#securing-elasticsearch-using-ufw-firewall)
*   [Searching Through Documents with Elasticsearch](#searching-through-documents-with-elasticsearch)
*   [Conclusion](#conclusion)

Are you looking for a way to optimize and improve your website’s performance? Why not install [Elasticsearch](https://www.elastic.co/elasticsearch/) on Ubuntu? Elasticsearch is a powerful open-source search engine that helps you index and searches through large amounts of data quickly and easily.

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

In this article, you’ll learn how to install Elasticsearch on Ubuntu and improve your website’s performance.

Read on to find out how to optimize your website like you never imagined!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following.

*   An Ubuntu server. This tutorial uses [Ubuntu](https://adamtheautomator.com/install-ubuntu/) 20.04.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

*   A user account with [root](https://linuxize.com/post/how-to-enable-and-disable-root-user-account-in-ubuntu/) privileges. Though this redundantly demonstrates `sudo` with the `root` account, typically `sudo` is only necessary for a less-privileged account.

## Installing Java on Ubuntu

Before getting your hands on Elasticsearch, you’ll first have to install Java on your server. Java installation is required for Elasticsearch to run.

You’ll install OpenJDK, the open-source Java Development Kit (JDK). This JDK is the recommended Java development environment for Elasticsearch.

> _While it’s possible to install Java after Elasticsearch, installing Java first is the best practice. Doing so ensures your environment is set up correctly and that there are no unexpected errors._

To install Java on your Ubuntu machine:

1\. Run the [apt update](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update) command to ensure your Ubuntu package repository is up-to-date.

```bash
sudo apt update -y
```

![Updating the Ubuntu Package Repository](https://adamtheautomator.com/wp-content/uploads/2022/04/image-644.png)

Updating the Ubuntu Package Repository

2\. Next, run the [apt install](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install) command to install OpenJDK (default-jdk).

You can install Java in other ways, but using the apt package manager is recommended to install Java on Ubuntu. apt ensures all required dependencies are installed.

```bash
sudo apt install default-jdk -y
```

![Installing OpenJDK](https://adamtheautomator.com/wp-content/uploads/2022/04/image-645.png)

Installing OpenJDK

Related:[Learning Ubuntu Apt Get Through Examples](https://adamtheautomator.com/ubuntu-apt-get/)

3\. Lastly, run the command below to check the installed version of Java.

```bash
java -version
```

As of this writing, the latest version below is 11.0.14.1, but yours might be different. This output indicates Java is installed correctly.

![Checking Installed Java Version](https://adamtheautomator.com/wp-content/uploads/2022/04/image-646.png)

Checking Installed Java Version

## **Install Elasticsearch on Ubuntu**

Now that Java is installe d, you can install Elasticsearch on your server. Elasticsearch is not available in the Ubuntu repositories, so you’ll install it from a third-party source.

1\. Run the [apt-get install](https://embeddedinventor.com/sudo-apt-get-install-command-explained-for-beginners/) command below to install the apt-transport-https package. This package secures the communication between your Ubuntu server and the package repository.

```bash
sudo apt-get install apt-transport-https -y
```

![Installing the apt-transport-https package](https://adamtheautomator.com/wp-content/uploads/2022/04/image-647.png)

Installing the apt-transport-https package

2\. Next, run the curl command below to add the Elasticsearch GPG key to your system (apt-key add). This key is used to verify the authenticity of the Elasticsearch package.

```bash
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
```

![Adding the Elasticsearch GPG Key](https://adamtheautomator.com/wp-content/uploads/2022/04/image-648.png)

Adding the Elasticsearch GPG Key

3\. After adding the GPG key, run the below command to add the latest Elasticsearch repository (https://artifacts.elastic.co/packages/7.x/apt stable main) to your system.

The -a flag is used to append the text to the /etc/apt/sources.list.d/elastic-7.x.list file. The elastic-7.x.list file is a list of files that contain a list of repositories, where your apt looks for packages to install.

> _Visit the [Elasticsearch repository](https://github.com/elastic/elasticsearch) page to find other repositories with different versions of Elasticsearch_

```bash
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
```

The repository is added to your system, but the new repository is unusable until you update your apt-cache.

![Adding the Elasticsearch Repository](https://adamtheautomator.com/wp-content/uploads/2022/04/image-649.png)

Adding the Elasticsearch Repository

4\. Now, run the [apt update](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update) command below to update your apt-cache.

```bash
sudo apt update -y
```

You can see in the output below that the Elasticsearch repository has been added to your system.

![Updating your apt-cache](https://adamtheautomator.com/wp-content/uploads/2022/04/image-650.png)

Updating your apt-cache

5\. Finally, run the [apt install](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install) command below to install Elasticsearch on your server.

```bash
sudo apt install elasticsearch -y
```

![Install Elasticsearch on Ubuntu](https://adamtheautomator.com/wp-content/uploads/2022/04/image-651.png)

Install Elasticsearch on Ubuntu

## **Configuring Elasticsearch**

You’ve completely installed Elasticsearch, but you’ll still have to configure Elasticsearch before using it. The main configuration file for Elasticsearch (_elasticsearch.yml_) is located in the _/etc/elasticsearch_ directory.

You can find all configuration options available in the _elasticsearch.yml_ file, and most of them are preconfigured. But you may need to change some of them according to your needs. And in this tutorial, you’ll only adjust the settings for the network host.

1\. Open the elasticsearch.yml file in your favorite text editor.

```bash
sudo nano /etc/elasticsearch/elasticsearch.yml
```

2\. Scroll down to the line that reads network.host, as shown below.

![Searching for the network.host Line](https://adamtheautomator.com/wp-content/uploads/2022/04/image-652.png)

Searching for the network.host Line

3\. Uncomment the network.host line by removing the leading # symbol and replacing its value with localhost. Doing so increases security by restricting outside access to your Elasticsearch instance.

Save the changes and exit your editor.

> _Note that any redundant spaces in this document will cause parsing issues, leading to an error. Never add any extra spaces at the beginning and end of any lines, and only use spaces between [dictionary keys and values](https://docs.saltproject.io/en/latest/topics/yaml/index.html#defining-yaml)._

![Editing elasticsearch.yml file](https://adamtheautomator.com/wp-content/uploads/2022/04/image-653.png)

Editing elasticsearch.yml file

4\. Now, run each systemctl command below to reload the daemon and restart the elasticsearch service so that your changes take effect.

These commands don’t have output. But at this point, your Elasticsearch instance on port 9200 is now configured to allow traffic only from machines on your local network.

> _On port 9200, Elasticsearch listens for traffic from everywhere by default._

```bash
# Reload deamon
sudo systemctl daemon-reload
# Restart the elasticsearch service
sudo systemctl restart elasticsearch
```

Related:[Controlling Systemd services with Ubuntu systemctl](https://adamtheautomator.com/ubuntu-systemctl/)

5\. Run the command below to start the elasticsearch service and verify the service is running.

```bash

sudo systemctl start elasticsearch
systemctl status elasticsearch
```

As shown below, the Elasticsearch service should be started with the status showing active (running).

![Starting the Elasticsearch Service](https://adamtheautomator.com/wp-content/uploads/2022/04/image-654.png)

Starting the Elasticsearch Service

6\. Lastly, run the following [netstat](https://www.geeksforgeeks.org/netstat-command-linux/) command to verify your Elasticsearch server is listening on the localhost interface on port 9200.

```bash
netstat -plntu | grep "9200"
```

You can see that the Elasticsearch process is running and listening on both the IPv6 and IPv4 loopback interfaces on port 9200, as shown below. 18718/java is the process ID (PID) for the Elasticsearch process.

![Verifying Elasticsearch Server is Listening on the localhost ](https://adamtheautomator.com/wp-content/uploads/2022/04/image-655.png)

Verifying Elasticsearch Server is Listening on the localhost

## **Securing Elasticsearch Using UFW Firewall**

Your Elasticsearch service is up, and naturally, you’d want to secure your Elasticsearch installation. But how? Ubuntu’s default firewall, UFW, is powerful enough and should suffice.

Your Elasticsearch server is accessible from the local network only, which is enough for developer and testing environments. But in a production environment, you’ll want to allow access to Elasticsearch only from specific hosts.

For example, your website may run on the server at 192.168.1.100, but you want to access the Elasticsearch data from a different machine on the network at 192.168.1.200. You can add a rule to allow traffic from 192.168.1.200 only.

Run the following command to add a UFW rule to allow traffic from `192.168.1.200` to your Elasticsearch instance on port `9200`. Replace the IP `192.168.1.200` address with the one you want to allow traffic from.

```bash
sudo ufw allow from 192.168.1.200 to any port 9200
```

![Allowing Traffic From 192.168.1.200](https://adamtheautomator.com/wp-content/uploads/2022/04/image-656.png)

Allowing Traffic From 192.168.1.200

Now, run the `ufw status` command below to check the status of your UFW firewall.

```bash
sudo ufw status verbose
```

The output below shows the rule you added is active.

![Checking UFW Firewall Status](https://adamtheautomator.com/wp-content/uploads/2022/04/image-657.png)

Checking UFW Firewall Status

> _Perhaps you want to remove a rule. If so, run the following command. Removing unused rules is highly recommended to keep your firewall tightened up. Replace IP\_ADD accordingly. sudo ufw delete allow from IP\_ADD to any port 9200_

## Searching Through Documents with Elasticsearch

Your Elasticsearch installation is now secure, so feel free to start using it, searching through documents with the `curl -XGET` command. But first, you’ll fetch nodes information in your Elasticsearch cluster you can use to debug problems with your Elasticsearch installation.

1\. Run either of the below curl commands to get information (-XGET) about the nodes in your Elasticsearch cluster in human-readable or YAML format.

```bash
# Get information about the nodes in your Elasticsearch cluster in human-readable format
curl -XGET 'http://localhost:9200/_nodes?pretty' 
# Get information about the nodes in your Elasticsearch cluster in YAML format
curl -XGET 'http://localhost:9200/_nodes?format=yaml'
```

You’ll see an output similar below when you choose the JSON format. You can use the JSON output below to debug problems with your Elasticsearch installation.

![Getting Nodes Information in the Elasticsearch Cluster (JSON format)](https://adamtheautomator.com/wp-content/uploads/2022/04/image-658.png)

Getting Nodes Information in the Elasticsearch Cluster (JSON format)

You’d get the below output instead if you choose the YAML format.

![Getting Nodes Information in the Elasticsearch Cluster (YAML format)](https://adamtheautomator.com/wp-content/uploads/2022/04/image-659.png)

Getting Nodes Information in the Elasticsearch Cluster (YAML format)

2\. Next, run the below curl command to add an index called ata. An index in Elasticsearch is like a ‘database’ in a relational database, such as MySQL.

This command adds a JSON document (application/json) to the ata index and makes it searchable. 1 is the unique identifier for the document in the ata index.

> _Documents in an index are usually stored in JSON (JavaScript Object Notation) format. Your e-commerce website, for example, can have one index with product data related and another index with customer data related._

```bash
curl -H 'Content-Type: application/json' -X POST 'http://localhost:9200/ata/task/1' -d '{ "name": "Go to the mall." }'
```

![Adding an Index Called ata](https://adamtheautomator.com/wp-content/uploads/2022/04/image-660.png)

Adding an Index Called ata

> _Note that your index name should be lowercase only. Uppercase letters are not allowed in index names, and the same goes with special characters like \\, /, \*, ?, “, <, >, |, \` \` (space character). You’ll get an error message like shown below if you try to create an index with a name that is not valid._

![Getting Index Naming Error](https://adamtheautomator.com/wp-content/uploads/2022/04/image-661.png)

Getting Index Naming Error

3\. Run the following curl command to search for the document you just created in step two in more concise and human-readable JSON output (?pretty).

```bash
curl -X GET 'http://localhost:9200/ata/task/1?pretty'
```

You will see the output in JSON format similar to the following.

![Search for the ata Index](https://adamtheautomator.com/wp-content/uploads/2022/04/image-662.png)

Search for the ata Index

4\. Now, run the command below to PUT a new value in the ata index with “Go to the supermarket”.

The PUT command replaces data in an existing document so long as you specify the same ID.

```bash
curl -X PUT "localhost:9200/ata/task/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "Go to the supermarket"
}
'
```

You can see below that this time the version number is 2. When you add a new document to an index, Elasticsearch sets the \_version field to 1. When you update a document, Elasticsearch sets the \_version field to 2.

The version number is incremented by one every time you update a document. This behavior lets you track the changes made to a document.

![Updating an Existing Document](https://adamtheautomator.com/wp-content/uploads/2022/04/image-663.png)

Updating an Existing Document

5\. Run the command below to DELETE the ata index. Deleting unused indexes lets you save disk space.

This command deletes everything related to the specified unused index, such as its documents, shards, and metadata. So be careful before you use this command.

```bash
curl -X DELETE "localhost:9200/ata?pretty"
```

![Delete the ata Index](https://adamtheautomator.com/wp-content/uploads/2022/04/image-664.png)

Delete the ata Index

6\. Finally, run the below command to check if the ata index is still available.

```bash
curl -X GET 'http://localhost:9200/ata?pretty'
```

You’ll get a 404 “not found” message, as shown below, which indicates ata index has been deleted successfully.

![Verifying ata Index is Deleted](https://adamtheautomator.com/wp-content/uploads/2022/04/image-665.png)

Verifying ata Index is Deleted

## Conclusion

In this article, you’ve learned how to install Elasticsearch on Ubuntu. You’ve added documents to an index, updated documents, and deleted unused indexes.

Elasticsearch is more than just a search engine that provides human-readable outputs in JSON and YAML format. Many data analysts, DevOps experts, and marketing professionals use Elasticsearch regularly.

Your Elasticsearch journey is just beginning. Why not start [performing text analysis on the Star Wars movies](https://opensourceconnections.com/blog/2015/09/18/the-simple-power-of-elasticsearch-analyzers/) to see what insights you can uncover? May the force be with you!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Finstall-elasticsearch-on-ubuntu%2F&text=Install%20Elasticsearch%20on%20Ubuntu%20for%20Next%20Level%20Searching)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Finstall-elasticsearch-on-ubuntu%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Finstall-elasticsearch-on-ubuntu%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2023/07/install-tensorflow-anaconda.jpg)

### [How to Install Tensorflow with Anaconda on Ubuntu](/install-tensorflow-with-anaconda/)

Get started with machine-learning platforms and install Tensorflow with Anaconda on Ubuntu Linux in this ATA Learning tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2022/04/Automate-your-Java-Builds-and-Install-Maven-on-Ubuntu.jpg)

### [Surefire Way to Install Maven on Ubuntu (Step by Step)](/install-maven-on-ubuntu/)

Learn how to install Apache Maven on Ubuntu and start simplifying and automating Java builds and code deployments in this step-by-step tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2022/03/Speed-and-Simplicity-with-the-Cinnamon-Desktop-Environment.jpg)

### [Speed and Simplicity with the Cinnamon Desktop Environment](/cinnamon-desktop-environment/)

Learn how to install, configure, and remotely connect to the Cinnamon desktop environment for quick files and application management in this step-by-step tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
