Elasticsearch is a popular, free and opensource product for search and analytics engine yet it is not available in the default package repository for CentOS, RHEL or Fedora. A public repository is however made available for yum / dnf by the company behind it which can be manually added to your system.

Elasticsearch is a Java application whereby you'll have to install a Java Runtime Environment prior to installing Elasticsearch. Both Elasticsearch and Java Runtime Environment can be installed from the command line using yum or dnf.

Step-by-step video guide:

Steps to install Elasticsearch on CentOS, RHEL or Fedora:

  1. Launch terminal.
  2. Install the latest Java Runtime Environment.
    $ sudo dnf install --assumeyes java-11-openjdk
    [sudo] password for user: 
    Last metadata expiration check: 1 day, 0:28:04 ago on Fri 30 Apr 2021 07:01:52 AM +08.
    Dependencies resolved.
     Package                  Arch   Version                        Repo       Size
     java-11-openjdk          x86_64 1:       appstream 260 k
    Installing dependencies:
     copy-jdk-configs         noarch 3.7-4.el8                      appstream  27 k
     java-11-openjdk-headless x86_64 1:       appstream  39 M
     javapackages-filesystem  noarch 5.3.0-1.module_el8.0.0+11+5b8c10bd
                                                                    appstream  30 k
     lksctp-tools             x86_64 1.0.18-3.el8                   baseos    100 k
     ttmkfdir                 x86_64 3.0.9-54.el8                   appstream  62 k
     tzdata-java              noarch 2021a-1.el8                    appstream 192 k
     xorg-x11-fonts-Type1     noarch 7.5-19.el8                     appstream 522 k
    Enabling module streams:
     javapackages-runtime            201801                                        
    Transaction Summary
    Install  8 Packages
    Total download size: 41 M
    Installed size: 173 M
    ##### snipped
  3. Download and install the public signing key for Elasticsearch repository.
    $ sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
  4. Create and add Elasticsearch repository for yum / dnf.
    $ sudo tee /etc/yum.repos.d/elasticsearch.repo <<EOF
    name=Elasticsearch repository for 7.x packages
  5. Install Elasticsearch package along with dependencies using dnf.
    $ sudo  dnf install --assumeyes elasticsearch
    Elasticsearch repository for 7.x packages        17 MB/s |  24 MB     00:01    
    Last metadata expiration check: 0:00:05 ago on Sat 01 May 2021 07:34:39 AM +08.
    Dependencies resolved.
     Package             Architecture Version         Repository               Size
     elasticsearch       x86_64       7.12.1-1        elasticsearch-7.x       311 M
    Transaction Summary
    Install  1 Package
    Total download size: 311 M
    Installed size: 518 M
    ##### snipped

    Even though dnf and yum supposedly resolve and install package dependencies, elasticsearch might not list java as a dependency thus you might come to this error if you don't manually install java as in the previous step.

    Running transaction
    which: no java in (/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin)
    could not find java; set JAVA_HOME or ensure java is in PATH
    error: %pre(elasticsearch-0:6.4.0-1.noarch) scriptlet failed, exit status 1
    Error in PREIN scriptlet in rpm package elasticsearch-6.4.0-1.noarch
      Verifying  : elasticsearch-6.4.0-1.noarch                             1/1
      elasticsearch.noarch 0:6.4.0-1

  6. Open Elasticsearch configuration file using your favorite 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 to listen on all available IP addresses in your system.


    Related: How to install Kibana on CentOS, Red Hat or Fedora

  7. Enable network access to Elasticsearch service on port 9200 and 9300 from the firewall.
    $ sudo firewall-cmd --permanent --add-port=9200/tcp
    # firewall-cmd --permanent --add-port=9300/tcp
  8. Reload firewall rules and keep state information.
    $ sudo firewall-cmd --reload
  9. Configure Elasticsearch service to automatically start during system boot.
    $ sudo systemctl enable elasticsearch
    Synchronizing state of elasticsearch.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
    Executing: /usr/lib/systemd/systemd-sysv-install enable elasticsearch
    Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /usr/lib/systemd/system/elasticsearch.service.
  10. Start Elasticsearch service.
    $ sudo systemctl start elasticsearch

    The service will take a while to start

  11. Access Elasticsearch service to test if installation is successful.
    $ curl
      "name" : "host",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "L0drd8tURQSPpAvNzboGwQ",
      "version" : {
        "number" : "7.12.1",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "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 not be able to connect immediately to Elasticsearch because the service takes quite a while to start and will get the following error if you try to connect immediately.

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

Comment anonymously. Login not required.