How to install ElasticSerach

Published on 19 April 2024

Welcome to our Elasticsearch installation guide! Regardless of your level of experience as a developer or your level of familiarity with search engines, Elasticsearch is a potent tool that can revolutionise your data handling. We’ll guide you through the entire setup process of Elasticsearch in this tutorial, enabling you to take advantage of all of its features for your projects.

Install Necessary Dependencies

Since Elasticsearch runs on top of Java, you need to install the Java Development Kit (JDK).

You can check if java is installed and the version on your Ubuntu machine with:

java -version

The output displays the installed version of Java.

If you do not have Java installed, you will get the standard bash message: bash: /usr/bin/java: No such file or directory

Before continuing with the installation, update the package index:

sudo apt update

To install default JDK, run the following command:

sudo apt install openjdk-8-jdk

When the process finishes, run the java -version command again. The output shows the following version in our case:

To allow access to your repositories via HTTPS, you need to install an APT transport package:

sudo apt install apt-transport-https

Install and Download Elasticsearch on Ubuntu

Add Elasticsearch Repository

First, update the GPG key for the Elasticsearch repository.

Use the wget command to pull the public key:

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

The output should display OK if everything went as it should.

Next, use this command to add the repository to your system.

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

Install Elasticsearch

Finally, it is time to install Elasticsearch.

Update the package index one more time before proceeding.

sudo apt update

Then, run the installation:

sudo apt install elasticsearch

Start Elasticsearch Service

After installation, Elasticsearch needs to be started in order to function. Additionally, the Elasticsearch service needs to be restarted after a computer reboot because it does not start by itself.

Use these commands to have Elasticsearch reload automatically the next time the system restarts:

First, reload the systemd configuration:

sudo systemctl daemon-reload

Then, enable the Elasticsearch service with:

sudo systemctl enable elasticsearch.service

And finally, after the service is enabled, start Elasticsearch:

sudo systemctl start elasticsearch.service

Allow Remote Access

It is not possible for other hosts to access your computer by default. Using your preferred text editor, open the elasticsearch.yml file to grant remote access.

sudo vi /etc/elasticsearch/elasticsearch.yml

Go to the Network section by swiping down. Look for the #network.host line.

After removing the pound (#) symbol from the line and setting the IP address to 0.0.0.0, add the following lines:

transport.host: localhost
transport.tcp.port: 9300
http.port: 9200

exit and save changes.

Test Elasticsearch

curl localhost:9200
or
http://localhost:9200/

Conclusion

Congratulations! You’ve successfully installed Elasticsearch and taken the first step towards unlocking its immense potential. As you’ve seen throughout this tutorial, Elasticsearch offers a wealth of features and capabilities that can revolutionize the way you handle data and search functionality in your projects.