How to install ElasticSearch On Centos

Step 1: Update CentOS 7 Linux

sudo yum -y update
sudo reboot

Step 2: Install Java on CentOS

sudo yum -y install java-1.8.0-openjdk  java-1.8.0-openjdk-devel

Set JAVA Path

cat <<EOF | sudo tee /etc/profile.d/java8.sh
export JAVA_HOME=/usr/lib/jvm/jre-openjdk
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar
EOF
source /etc/profile.d/java8.sh

Step 3: Add ElasticSearch Yum repository

cat <<EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/oss-7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

Step 4: Install ElasticSearch on CentOS

sudo yum -y install elasticsearch-oss

Step 5: Enable ElasticSearch on Centos

sudo systemctl enable --now elasticsearch

Step 6: Check if ElasticSearch Running

curl http://127.0.0.1:9200

Check more on Elasticsearch commands here.

How to install ElasticSearch On Ubuntu

Step 1: Add Elastic source list to the sources.list.d

curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add 
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

Step 2: Update Apt

sudo apt update

Step 3: Install Elasticsearch

sudo apt install elasticsearch

Step 4: Enable Elasticsearch On Ubuntu

sudo systemctl enable --now elasticsearch

Step 4: Check if Elasticsearch running On Ubuntu

curl http://127.0.0.1:9200