5

I have Ubuntu 16.04 LTS on virtual box and I'd like to install elasticsearch in order to use it with Ruby on Rails. I've done a search on google on how to do the installation, but I have found mutiple guides that have a few differences which got me a little bit confused, for instance:

Installing elasticsearch on Ubuntu 16.04

Digital Ocean: Install and Configure Elasticsearch on Ubuntu 16.04

(see @ Prerequisites)

How should I install elasticsearch safely, without messing up my development environment?

2
  • If my solution worked for your problem, could you please accept the answer? In that way people know if the problem is solved. Thank you Oct 20 '17 at 14:31
  • 1
    Sorry I missed you
    – ltdev
    Oct 20 '17 at 14:43
14

Elastic has their own guide to install elasticsearch with Debian packages. you can find it on their website.

https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html

I used this one and now everything works like a charm.

Elasticsearch requires Java 8 or later:

$ sudo apt-get install openjdk-8-jdk
$ java -version
openjdk version "1.8.0_111"

Install Elasticsearch

$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
$ sudo apt-get install apt-transport-https
$ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
$ sudo apt-get update && sudo apt-get install elasticsearch

some remarks (from elastic website):

  • Do not use add-apt-repository as it will add a deb-src entry as well, but we do not provide a source package. If you have added the deb-src entry, you will see an error like the following:
Unable to find expected entry 'main/source/Sources' in Release file
Wrong sources.list entry or malformed file)

=> Delete the deb-src entry from the /etc/apt/sources.list file and the installation should work as expected.

  • If two entries exist for the same Elasticsearch repository, you will see an error like this during apt-get update:

Duplicate sources.list entry https://artifacts.elastic.co/packages/5.x/apt/ ...`

=> Examine /etc/apt/sources.list.d/elasticsearch-5.x.list for the duplicate entry or locate the duplicate entry amongst the files in /etc/apt/sources.list.d/ and the /etc/apt/sources.list file

0
3

For very basic installation of ElasticSearch 1.x or 2.x on Ubuntu 16.04

(the same goes for Ubuntu 14.04) do the next few steps on fresh install Ubuntu:

  1. sudo apt-get update

  2. sudo apt-get upgrade

  3. sudo add-apt-repository ppa:webupd8team/java

  4. sudo apt-get update

  5. sudo apt-get install oracle-java8-installer

  6. java -version

//For 2.x; elasticsearch 2.4.0

  1. wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.0/elasticsearch-2.4.0.deb

  2. sudo dpkg -i elasticsearch-2.4.0.deb

  3. service elasticsearch status

  4. sudo apt-get install -y curl lynx links

  5. lynx http : // localhost : 9200

OR

  1. curl -X GET 'http : // localhost:9200'
2

Installing ElasticSearch 6.8.6 on Ubuntu 16

The latest version at the time of writing was 7 but we needed version 6 for compatibility reasons so using the typical apt-get package manager wouldn't work. Instead we opted to install the package directly.

  1. Download and install the debian package for version 6.8.6:

    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.6.deb
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.6.deb.sha512
    shasum -a 512 -c elasticsearch-6.8.6.deb.sha512 
    sudo dpkg -i elasticsearch-6.8.6.deb
    
  2. Setup elasticsearch to start automatically on boot.

    sudo /bin/systemctl daemon-reload
    sudo /bin/systemctl enable elasticsearch.service
    
  3. Start the elasticsearch service.

    bash
    sudo systemctl start elasticsearch.service
    
  4. Confirm elasticsearch is running:

    $ curl -X GET "localhost:9200/?pretty"
    {
      "name" : "dfdnndd",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "abcdadsf123234234",
      "version" : {
        "number" : "6.8.6",
        "build_flavor" : "default",
        "build_type" : "deb",
        "build_hash" : "3d9f765",
        "build_date" : "2019-12-13T17:11:52.013738Z",
        "build_snapshot" : false,
        "lucene_version" : "7.7.2",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    } 
    

    NOTE: Sometimes it takes a few seconds to spin up.

  5. Configure as necessary:

    vi /etc/elasticsearch/elasticsearch.yml
    

    For example, uncomment this line, #network.host: localhost, and replace localhost with your server's IP address so it looks someting like this: network.host: 123.123.123.123.

0

Elasticsearch 7.x installation on Ubuntu 20.04

  • Installing openjdk 11 (8th version also have been used without issues):

      sudo apt install openjdk-11-jre-headless
    
  • Elasticsearch installation

      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
      sudo apt update
      sudo apt install elasticsearch
    
  • Configure elasticsearch configuration file /etc/elasticsearch/elasticsearch.yml

      cluster.name: myclaster
      node.name: mynode1
      network.host: 192.168.0.5
    

    Uncomment the above option and specify your IP address or just localhost if you do not desire to give access to it through your local network.

  • If you desire to allow access to it from your local network, then specify only IP addresses of specific machine you want to grant access from:

      sudo ufw allow from 192.168.0.55 to any port 9200
    

    Do not allow access from any host, because of it does not have restrictions.

  • Start elasticsearch service:

      sudo systemctl start elasticsearch
    
  • Test if your elasticsearch service is running using telnet from both machines (192.168.0.5 and 192.168.0.55):

      telnet 192.168.0.5 9200
    

    You'll get the next

      Trying 192.168.0.5...
      telnet: Unable to connect to remote host: Connection refused
    

    if elasticsearch service is not running

    You'll get the next if it is running but blocked by firewall:

      Trying 192.168.0.5...
      telnet: Unable to connect to remote host: Connection timed out
    

    You'll get the next output if the service is running and it is allowed in firewall:

      Trying 192.168.0.5...
      Connected to 192.168.0.5.
      Escape character is '^]'.
    
  • Test elasticsearch configuration by:

      curl -X GET 'http://192.168.0.5:9200'
    

More details here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.