How to Install Elasticsearch on Ubuntu 21.04

Elasticsearch is a highly scalable open-source full-text search and analytics engine. It allows you to store, search, and analyze big volumes of data quickly and in near real time. Elasticsearch is an open source developed in Java and used by many big organizations around the world.

Install OpenJDK 8

First, update the packages index and install the OpenJDK 8 with following commands.

apt update

apt install openjdk-8-jdk


root@vps:~# apt install openjdk-11-jdk
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  eatmydata libeatmydata1 python3-certifi python3-importlib-metadata python3-jinja2 python3-json-pointer
  python3-jsonpatch python3-jsonschema python3-markupsafe python3-more-itertools python3-pyrsistent
  python3-requests python3-urllib3 python3-zipp
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  at-spi2-core ca-certificates-java fontconfig-config fonts-dejavu-core fonts-dejavu-extra java-common
  libatk-bridge2.0-0 libatk-wrapper-java libatk-wrapper-java-jni libatk1.0-0 libatk1.0-data libatspi2.0-0
  libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libdrm-amdgpu1 libdrm-intel1
  libdrm-nouveau2 libdrm-radeon1 libfontconfig1 libfontenc1 libgif7 libgl1 libgl1-mesa-dri libglapi-mesa
  libglvnd0 libglx-mesa0 libglx0 libgraphite2-3 libharfbuzz0b libice-dev libice6 libjpeg-turbo8 libjpeg8
  liblcms2-2 libllvm11 libpciaccess0 libpcsclite1 libpthread-stubs0-dev libsensors-config libsensors5

  0 upgraded, 88 newly installed, 0 to remove and 1 not upgraded.
  Need to get 299 MB of archives.
  After this operation, 574 MB of additional disk space will be used.
  Do you want to continue? [Y/n] y

After installation check the version of the JAVA.

java -version


root@vps:~# java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2, mixed mode, sharing)

Install Elasticsearch

Import GPG key for Elasticsearch packages.

wget -qO - | apt-key add -


root@vps:~# wget -qO - | sudo apt-key add -

Next, add the Elasticsearch repository to the system by following command.

sh -c 'echo "deb stable main" > /etc/apt/sources.list.d/elastic-6.x.list'

After adding the repository to your system. Update cache and then install Elasticsearch packages on your system.

apt update 

apt install elasticsearch

After installing Elasticsearch package, Statr and enable the elasticsearch service with following command.

systemctl start elasticsearch.service

systemctl enable elasticsearch.service


root@vps:~# systemctl enable elasticsearch.service
Synchronizing state of elasticsearch.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable elasticsearch
Created symlink /etc/systemd/system/ → /lib/systemd/system/elasticsearch.service.

Configure Elasticsearch

Once the elasticsearch has been installed on your system, open the elasticsearch.yml configuration file.

vi /etc/elasticsearch/elasticsearch.yml 

Search for the line that contains, uncomment it, and change the value to

Set the network host to to listen on all interfaces and make it available publicly,

Incase you want to configure this to be private/local to your machine. You will have to set the to, so the content is not public.

Save and exit the file once modified and restart the Elasticsearch service for the changes to take effect.

systemctl restart elasticsearch

Enter it into your browser's to the server hostname or IP addressed followed by port #9200



  "name" : "SCEC42D",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "CFBSkdNUTIWdngyr_6aRRw",
  "version" : {
    "number" : "6.8.15",
    "build_flavor" : "default",
    "build_type" : "deb",
    "build_hash" : "c9a8c60",
    "build_date" : "2021-03-18T06:33:32.588487Z",
    "build_snapshot" : false,
    "lucene_version" : "7.7.3",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  "tagline" : "You Know, for Search"