Installing ElasticSearch On ubuntu 16.04 and 14.04
Updated On DEC 2016: Installation Script In Method 2 updated for installation of elastic search 5.x
Elasticsearch is a highly scalable open-source full-text search and analytics engine build on top of Apache Lucene(A free and open-source information retrieval software library). It allows you to store, search, and analyze big volumes of data quickly and in near real time. It is generally used as the underlying engine/technology that powers applications that have complex search features and requirements.
Here we are going to see, How to install and setup elasticsearch on Ubuntu Linux 16.04 and 14.04..
Here I am going to show you two ways to install elasticsearch on Ubuntu Linux..
The first one is manual installation of elasticsearch.. You have to follow instructions one by one ..
The second one is an easy way, there we use shell-script to install the elasticsearch as it would take care of all things.. The script will install and setup elasticsearch for you..
Installation :
Method 1 :
First things first, Before we start to install elasticsearch, we need to install Java Runtime Environment (JRE).. because Elasticsearch itself written in the Java. (Elasticsearch requires Java 7 or higher).
This step shows you how to install OpenJDK-8.
First, update the list of available packages by running apt-get update.
sudo apt-get update
Then, install OpenJDK with the command:
For Ubuntu 16.04 :
sudo apt-get -y install openjdk-8-jdk openjdk-8-jre
For Ubuntu 14.04 :
sudo add-apt-repository -y ppa:openjdk-r/ppa && sudo apt-get update && sudo apt-get -y install openjdk-8-jdk openjdk-8-jre
To verify your JRE is installed and can be used, run the command: java -version
The result should look like this:
sudo update-alternatives --config java
Now, select apropriate version of JAVA..to verify the java version run..
java -version
Download and Install Elasticsearch :
Elasticsearch can be downloaded directly from official site as zip, tar.gz and deb
I will recommend.. Installing from zip or tar archive.. Because as far as I knew it is the best way to get Elasticsearch on Ubuntu ... from my experience the another way (installing from .deb) is very worst... has many nasty issues(tried on Ubuntu 16.04)..
Download the archive
cd && wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/zip/elasticsearch/2.3.5/elasticsearch-2.3.5.zip
The above command downloads the zip archive, make sure that you have unzip installed in your system... if don't have installed unzip in your system.. run the following command.. to install unzip
sudo apt-get install unzip
Now unzip/decompress the downloaded archive.. you can do this with command given below..
unzip elasticsearch-2.3.5.zip
Move Extracted/unzipped directory to /opt :
We don't want to pollute our home folder and make it ugly with too many folders apart from default one.. and moving elasticsearch to /opt directory will also make it available to other users in your system too..
sudo rm -r /opt/elasticsearch-2*
Now move newly extracted elasticsearch directory to /opt with following command..
sudo mv elasticsearch-2.3.5/ /opt/
Now your elasticsearch is ready to use, You can run it with following command..
/opt/elasticsearch-2.3.5/bin/elasticsearch
But it's so convenient, if we can able to start it from commandline.. by simply typing 'elasticsearch' .. just like normal system commands.. to do so.. we have to create a symbolic link for elasticsearch in /bin folder.. Run following commands....
First remove symbolic link if one already exists..
sudo rm /bin/elasticsearch
now.. create new symbolic link ...
sudo ln -s /opt/elasticsearch-2.3.5/bin/elasticsearch /bin/
That's it .. now you can start elasticsearch just by typing "elasticsearch" in your terminal window..
Now the other method (method 2) show you the easiest way of getting elasticsearch up and running on your Ubuntu installation..
Method 2 :
In this method ... You just need to run the following code ... the script will take care of remaining things..
wget -O - https://raw.githubusercontent.com/shivarajnaidu/UV-Shell-Scripts/master/ElasticSearch-Installation-Scripts/elasticsearch-installation-script-for-ubuntu.sh | bash -s
Update :
The installation script is updated to support installation of elasticsearch v5.x. If you want to install elasticsearch 5.x, just run above command with argument '5' (with out quotes).
wget -O - https://raw.githubusercontent.com/shivarajnaidu/UV-Shell-Scripts/master/ElasticSearch-Installation-Scripts/elasticsearch-installation-script-for-ubuntu.sh | bash -s 5
Test your Elasticsearch installation
Start elasticsearch by typing "elasticsearch" on your command-line..
Let's ensure that everything is working well... open terminal and Run following..
elasticsearch
To test elasticsearch run following command in terminal..
curl -X GET 'http://localhost:9200'
or even you can check from your web browser by visiting http://localhost:9200
if elasticsearch works well.. You should see the following response..