elasticsearchelasticsearch-rails

Uninstall elasticsearch from /usr/local/var and install another version on MacOSX


I was trying to downgrade elasticsearch from 6.8.4 to 5.6 on my Mac machine. But somehow I mess with the existing installation of 6.8.4 and now neither I am able to fix the current installed version nor I am able to install 5.6

Details:

I had 6.8.4 installed correctly on my system and I was successfully able to hit http://localhost:9200/ port and see the version info and every other details. But due to a dependency, I had to downgrade the version to 5.6

I followed this guide https://gist.github.com/govindpatel/0660b33a343b807664972b53c3b12ca0 and messed with the installation of 6.8.4 by removing plist entry and other details. Now when I try to start elasticsearch service by typing $ elasticsearch I get: -bash: elasticsearch: command not found and $ brew service restart elasticsearch gives me Error: Unknown command: service

However, I can still see 6.8.4 when I fire this command:

$ brew info elasticsearch
elasticsearch: stable 6.8.4, HEAD
Distributed search & analytics engine
https://www.elastic.co/products/elasticsearch
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/elasticsearch.rb
==> Requirements
  Required: java = 1.8 ✔
==> Options
  --HEAD
  Install HEAD version
==> Caveats
  Data:    /usr/local/var/lib/elasticsearch/
  Logs:    /usr/local/var/log/elasticsearch/elasticsearch_Puneet.log
  Plugins: /usr/local/var/elasticsearch/plugins/
  Config:  /usr/local/etc/elasticsearch/


To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch
==> Analytics
  install: 8,690 (30 days), 23,748 (90 days), 122,267 (365 days)
  install_on_request: 8,233 (30 days), 22,565 (90 days), 114,157 (365 days)
  build_error: 0 (30 days)

I've even tried installing 5.6 (via Homebrew) - brew install elasticsearch@5.6 and set the PATH at first place in ~/.bash_profile but no luck! :(

Please help and advise on:

  1. How can I fix the existing 6.8.4 version, and
  2. How can I downgrade it systematically (because existing conf, data lies under /usr/local folder)

Current details: to see if elasticsearch is running: $ launchctl list | grep elasticsearch, I am getting: - 1 homebrew.mxcl.elasticsearch@5.6 and I do not have this currently installed (o/p attached) - $ brew uninstall elasticsearch@5.6 ~> Error: No such keg: /usr/local/Cellar/elasticsearch@5.6

[UPDATE-1]

After posting this, I tried running the ES installation command again: brew install elasticsearch

Updating Homebrew...
==> Auto-updated Homebrew!
  Updated 2 taps (homebrew/core and homebrew/cask).
  No changes to formulae.

==> Downloading 
  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-6.8.4.tar.gz
Already downloaded: /Library/Caches/Homebrew/downloads/elasticsearch-oss-6.8.4.tar.gz
==> Caveats
  Data:    /usr/local/var/lib/elasticsearch/
  Logs:    /usr/local/var/log/elasticsearch/elasticsearch_Puneet.log
  Plugins: /usr/local/var/elasticsearch/plugins/
  Config:  /usr/local/etc/elasticsearch/

To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch
==> Summary
  🍺    /usr/local/Cellar/elasticsearch/6.8.4: 133 files, 103.2MB, built in 6 seconds

and then started the service $ brew services start elasticsearch ~> ==> Successfully startedelasticsearch(label: homebrew.mxcl.elasticsearch). Now when I tried accessing the port: http://localhost:9200 -- it's working (install from 0 fixed this though!)

{
  "name" : "DwQRyf7",
  "cluster_name" : "elasticsearch_Puneet",
  "cluster_uuid" : "hLAu9onQSiuQHOpm_e9IKw",
  "version" : {
    "number" : "6.8.4",
    "build_flavor" : "oss",
    "build_type" : "tar",
    "build_hash" : "bca0c8d",
    "build_date" : "2019-10-16T06:19:49.319352Z",
    "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"
}

The only question remains now is, how can I downgrade it systematically?

[UPDATE-2]

Now that I have 6.8.4 with me, I've checked for other versions with: brew search elasticsearch and got 5.6. Then I installed 5.6 with brew install elasticsearch@5.6

Updating Homebrew...
==> Auto-updated Homebrew!
  Updated 1 tap (homebrew/cask).
  No changes to formulae.
==> Downloading https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.16.tar.gz
  Already downloaded: /Library/Caches/Homebrew/downloads/3d7cc028f605699065bd403b0a2383db8d7413c570df57e26fc87a735126c96c--elasticsearch-5.6.16.tar.gz
==> Caveats
  Data:    /usr/local/var/elasticsearch/elasticsearch_Puneet/
  Logs:    /usr/local/var/log/elasticsearch/elasticsearch_Puneet.log
  Plugins: /usr/local/opt/elasticsearch@5.6/libexec/plugins/
  Config:  /usr/local/etc/elasticsearch/
  plugin script: /usr/local/opt/elasticsearch@5.6/libexec/bin/elasticsearch-plugin

elasticsearch@5.6 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have elasticsearch@5.6 first in your PATH run:
  echo 'export PATH="/usr/local/opt/elasticsearch@5.6/bin:$PATH"' >> ~/.bash_profile


To have launchd start elasticsearch@5.6 now and restart at login:
  brew services start elasticsearch@5.6
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/elasticsearch@5.6/bin/elasticsearch
==> Summary
  🍺  /usr/local/Cellar/elasticsearch@5.6/5.6.16: 106 files, 36.0MB, built in 6 seconds

Then I added 5.6 to $PATH. Now, when I am trying to switch elasticsearch version using brew switch elasticsearch 5.6 I am getting:

Error: elasticsearch does not have a version "5.6" in the Cellar.
elasticsearch installed versions: 6.8.4

Any idea what I am missing here?


Solution

  • Looks like I found the solution after troubleshooting for a while.

    In order to maintain multiple versions of elasticsearch on your development machine, here's what you need to do:

    Let's say I have 6.8.4 installed and I want another version as well. In order to maintain both, first check what all versions your system (mac) has by typing: brew search elasticsearch and my system have 3 versions supported for ES:

    1. elasticsearch - Latest and stable (already installed)
    2. elasticsearch@2.4
    3. elasticsearch@5.6

    In order to have 2.4, here's what you'll have to do:

    $ brew install elasticsearch@2.4
    # After installation type:
    $ brew services stop elasticsearch
    # above command will stop elasticsearch (lastest stable) service
    # add 2.4 to $PATH
    $ echo 'export PATH="/usr/local/opt/elasticsearch@2.4/bin:$PATH"' >> ~/.bash_profile
    # start the service of 2.4
    $ brew services start elasticsearch@2.4
    # check for the service/installation
    $ launchctl list | grep elasticsearch
    # above command should show you a port
    

    Now you can hit http://localhost:9200 in browser and it should show you 2.4

    To switch back to latest stable version:

    $ brew services stop elasticsearch
    # remove entry from $PATH variable
    $ brew services start elasticsearch
    

    It seems to me that brew switch elasticsearch [VERSION] does not work