How to Install Elasticsearch on Ubuntu 20.04

Install Elasticsearch on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure Elasticsearch on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Elasticsearch is a platform for distributed search and analysis of data in real-time. It is a popular choice due to its usability, powerful features, and scalability. With Elasticsearch, you can store, search, and analyze big volumes of data faster and in near real-time. Elasticsearch is generally used as the underlying engine/technology that powers applications that have complex search features and requirements.

Install Elasticsearch on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install Java.

Elasticsearch is based on Java and requires Java to be installed. You can either install Oracle Java Standard Edition 8 or use the open-source version of Java called OpenJDK 8:

sudo apt install openjdk-8-jdk

You can verify that we have Java installed by running this command:

$ java -version

Step 3. Install Elasticsearch on the Ubuntu system.

Now we add Elasticsearch GPG key:

wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -

After importing its GPG key, run the commands below to add its package repository:

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

Once the repository is enabled, update the apt package list and install the Elasticsearch engine by typing:

sudo apt update
sudo apt install elasticsearch

After that installing Elasticsearch package, you can use the commands below to make sure it automatically starts up when the server boots up and start it:

sudo systemctl start elasticsearch.service
sudo systemctl enable elasticsearch.service

Step 4. Configure Elasticsearch.

You can customize this by editing the Elasticsearch configuration file. Edit configuration file in your favourite text editor and update the following values:

sudo nano /etc/elasticsearch/elasticsearch.yml

Change the following values:

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0    
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.

Restart the Elasticsearch service for the changes to take effect:

sudo systemctl restart elasticsearch

Step 5. Test Elasticsearch Setup.

You can verify that Elasticsearch is running by sending an HTTP request to port 9200 on localhost with the following curl command:

curl -X GET "localhost:9200/"

You should see something similar to this:

{
  "name" : "kwweoeQ",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "B-5BmaiannaD3ww",
  "version" : {
    "number" : "6.6.1",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "1f888f69",
    "build_date" : "2020-06-11T17:10:46.180291Z",
    "build_snapshot" : false,
    "lucene_version" : "7.6.0",
    "minimum_wire_compatibility_version" : "5.8.0",
    "minimum_index_compatibility_version" : "5.4.0"
  },
  "tagline" : "You Know, for Search"
}

That’s all you need to do to install Elasticsearch on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.