DEV Community

Cover image for Setup ElasticSearch Ubuntu / Mac
Daniyal Haider
Daniyal Haider

Posted on

Setup ElasticSearch Ubuntu / Mac

ElasticSearch on ubuntu

For installation run these commands

sudo apt-get install elasticsearch
sudo systemctl daemon-reload
Enter fullscreen mode Exit fullscreen mode

To automatically start elasticsearch when system reboots

sudo systemctl enable elasticsearch.service 
Enter fullscreen mode Exit fullscreen mode

Navigate to file /etc/elasticsearch/elasticsearch.yml
Edit the file and uncomment following lines

# network.host: localhost
# http.port: 9200
Enter fullscreen mode Exit fullscreen mode

Change to the following (make sure not leave any space)

network.host: localhost
http.port: 9200
Enter fullscreen mode Exit fullscreen mode

Add new line

discovery.type: single-node
Enter fullscreen mode Exit fullscreen mode

Navigate to file /etc/elasticsearch/jvm.options
Add the following lines

-Xms2g
-Xmx4g
Enter fullscreen mode Exit fullscreen mode

You can change the above two lines according to your system's memory, here 2g represents 2GB. -Xms2g is a minimum of 2GB assigned to ES and -Xsmx4g is a maximum of 4GB assigned.

If you want to assign memory in MBs you can use
-Xms512m will give a minimum of 512MB memory to ES.

NOTE: While removing comments from the files mentioned above. be careful not to leave any spaces from the line start this would not allow ElasticSearch to start

Run the following command to start

sudo systemctl start elasticsearch
curl http://localhost:9200/
Enter fullscreen mode Exit fullscreen mode

Run this command to see the health of your ES cluster

curl -XGET 'localhost:9200/_cluster/health?pretty=true'
Enter fullscreen mode Exit fullscreen mode

Plugin install in case of error:400

sudo /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu
Enter fullscreen mode Exit fullscreen mode

For uninstallation run these commands

sudo apt-get remove --purge elasticsearch
sudo rm -rf /etc/elasticsearch
sudo rm -rf /var/lib/elasticsearch
Enter fullscreen mode Exit fullscreen mode

ElasticSearch on MacBook / HomeBrew

Elastic publishes Homebrew formulae so you can install Elasticsearch with the Homebrew package manager.

To install with Homebrew, you first need to tap the Elastic Homebrew repository:

brew tap elastic/tap
Enter fullscreen mode Exit fullscreen mode

Once you’ve tapped the Elastic Homebrew repo, you can use brew install to install the latest version of Elasticsearch:

brew install elastic/tap/elasticsearch-full
Enter fullscreen mode Exit fullscreen mode

To install the Elasticsearch plugin on Mac use the following command

/usr/local/var/homebrew/linked/elasticsearch-full/bin/elasticsearch-plugin install <plugin_name>
Enter fullscreen mode Exit fullscreen mode

Note that the path to bin may vary according to your system
/usr/local/var/homebrew/linked/elasticsearch-full/bin

Top comments (0)