Elasticsearch is available on Github but is not available in the default apt repository for Ubuntu or Debian. However, Elastic, the company behind Elasticsearch, hosts a public repository that you can add to your system to install Elasticsearch via apt.

It is developed using Java; thus, you'll need to install Java Runtime Environment before installing Elasticsearch. Both Java Runtime Environment and Elasticsearch can be installed from the terminal using apt.

Step-by-step video guide:

Steps to install Elasticsearch on Ubuntu or Debian:

  1. Add GPG key of Elasticsearch's repository.
    $ wget --quiet --output-document=- https://artifacts.elastic.co/GPG-KEY-elasticsearch | gpg --dearmor | sudo tee /usr/share/keyrings/elasticsearch-archive-keyring.gpg
    [sudo] password for user:
  2. Add Elasticsearch's repository to apt's.
    $ echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
    deb https://artifacts.elastic.co/packages/7.x/apt stable main
    [sudo] password for user:
    deb https://artifacts.elastic.co/packages/7.x/apt stable main
  3. Update list of available packages from the newly added repository.
    $ sudo apt update
    Hit:1 https://artifacts.elastic.co/packages/7.x/apt stable InRelease
    Hit:2 http://archive.ubuntu.com/ubuntu hirsute InRelease
    Get:3 http://security.ubuntu.com/ubuntu hirsute-security InRelease [101 kB]
    Get:4 http://archive.ubuntu.com/ubuntu hirsute-updates InRelease [109 kB]
    Hit:5 http://archive.ubuntu.com/ubuntu hirsute-backports InRelease 
    Fetched 209 kB in 1s (157 kB/s)                          
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    All packages are up to date.
  4. Install latest Java Runtime Environment.
    $ sudo apt install --assume-yes default-jre
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    The following additional packages will be installed:
      ca-certificates-java default-jre-headless fonts-dejavu-extra java-common
      libatk-wrapper-java libatk-wrapper-java-jni openjdk-11-jre
      openjdk-11-jre-headless
    Suggested packages:
      fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei
      | fonts-wqy-zenhei
    The following NEW packages will be installed:
      ca-certificates-java default-jre default-jre-headless fonts-dejavu-extra
      java-common libatk-wrapper-java libatk-wrapper-java-jni openjdk-11-jre
      openjdk-11-jre-headless
    0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
    Need to get 39.6 MB of archives.
    After this operation, 179 MB of additional disk space will be used.
    ##### snipped
  5. Install Elasticsearch package using apt.
    $ sudo apt install --assume-yes elasticsearch
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    The following NEW packages will be installed:
      elasticsearch
    0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
    Need to get 326 MB of archives.
    ##### snipped
  6. Enable access to port 9200 and 9300 from the local firewall.
    $ sudo ufw allow 9200
    Rules updated
    Rules updated (v6)
    $ sudo ufw allow 9300
    Rules updated
    Rules updated (v6)
  7. Open Elasticsearch configuration file using your preferred text editor to edit configuration options if necessary.
    $ sudo vi /etc/elasticsearch/elasticsearch.yml

    Listen to host's IP address to enable connection from remote host or use 0.0.0.0 to listen on all available IP addresses in your system.

    network.host: 0.0.0.0

    Related: How to install Kibana on Ubuntu or Debian

  8. Configure Elasticsearch to automatically start during boot.
    $ sudo systemctl enable elasticsearch
    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/multi-user.target.wants/elasticsearch.service → /lib/systemd/system/elasticsearch.service.
  9. Start Elasticsearch service.
     $ sudo systemctl start elasticsearch
  10. Query Elasticsearch service to test if installation was successful.
    $ curl 127.0.0.1:9200
    {
      "name" : "host",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "NqCDFByvRKWPcjO1z09hmg",
      "version" : {
        "number" : "7.12.1",
        "build_flavor" : "default",
        "build_type" : "deb",
        "build_hash" : "3186837139b9c6b6d23c3200870651f10d3343b7",
        "build_date" : "2021-04-20T20:56:39.040728659Z",
        "build_snapshot" : false,
        "lucene_version" : "8.8.0",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }

    You will get the following error if you immediately test the service after starting it up because Elasticsearch takes a while to start.

    curl 127.0.0.1:9200
    curl: (7) Failed to connect to 127.0.0.1 port 9200: Connection refused
Discuss the article:

Comment anonymously. Login not required.

Share!