title: Can not start elasticsearch as a service in ubuntu 16.04
body: <p>I have recently upgraded my machine from Ubuntu <code>14.04</code> to <code>16.04</code>. I am facing problem of using the <code>elasticsearch</code> as a service. I <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html" rel="noreferrer">installed</a> <code>elasticsearch</code> using:</p>
  
  <pre><code>sudo apt-get install elasticsearch
  </code></pre>
  
  <p>Now <code>sudo service elasticsearch status</code> command shows me this result:</p>
  
  <pre><code>elasticsearch.service - LSB: Starts elasticsearch
     Loaded: loaded (/etc/init.d/elasticsearch; bad; vendor preset: enabled)
     Active: active (exited) since Sat 2016-07-30 18:28:13 BDT; 1h 19min ago
       Docs: man:systemd-sysv-generator(8)
   Main PID: 7988 (code=exited, status=1/FAILURE)
     CGroup: /system.slice/elasticsearch.service
  
  Jul 30 18:28:13 dimik elasticsearch[10266]: [warning] /etc/init.d/elasticsearch: No java runtime was found
  Jul 30 18:28:13 dimik systemd[1]: Started LSB: Starts elasticsearch.
  Jul 30 18:28:46 dimik systemd[1]: Started LSB: Starts elasticsearch.
  Jul 30 18:35:30 dimik systemd[1]: Started LSB: Starts elasticsearch.
  Jul 30 19:04:36 dimik systemd[1]: Started A search engine.
  Jul 30 19:07:48 dimik systemd[1]: Started A search engine.
  Jul 30 19:27:01 dimik systemd[1]: Started A search engine.
  Jul 30 19:27:51 dimik systemd[1]: Started A search engine.
  Jul 30 19:28:54 dimik systemd[1]: Started A search engine.
  Jul 30 19:29:18 dimik systemd[1]: Started LSB: Starts elasticsearch.
  </code></pre>
  
  <p>Although Java is installed in my machine and I can start the server using this command.</p>
  
  <pre><code>sudo /usr/share/elasticsearch/bin/elasticsearch
  </code></pre>
  
  <p>I am kind of stuck here. Any help will be appreciated. </p>
  
  <p><strong>Edit</strong></p>
  
  <p>After setting up <code>JAVA_HOME</code> for root the error:</p>
  
  <pre><code>elasticsearch.service - LSB: Starts elasticsearch
     Loaded: loaded (/etc/init.d/elasticsearch; bad; vendor preset: enabled)
     Active: active (exited) since Sat 2016-07-30 18:28:13 BDT; 3h 32min ago
       Docs: man:systemd-sysv-generator(8)
   Main PID: 7988 (code=exited, status=1/FAILURE)
     CGroup: /system.slice/elasticsearch.service
  
  Jul 30 18:35:30 dimik systemd[1]: Started LSB: Starts elasticsearch.
  Jul 30 19:04:36 dimik systemd[1]: Started A search engine.
  Jul 30 19:07:48 dimik systemd[1]: Started A search engine.
  Jul 30 19:27:01 dimik systemd[1]: Started A search engine.
  Jul 30 19:27:51 dimik systemd[1]: Started A search engine.
  Jul 30 19:28:54 dimik systemd[1]: Started A search engine.
  Jul 30 19:29:18 dimik systemd[1]: Started LSB: Starts elasticsearch.
  Jul 30 20:02:07 dimik systemd[1]: Started LSB: Starts elasticsearch.
  Jul 30 20:20:21 dimik systemd[1]: Started LSB: Starts elasticsearch.
  Jul 30 21:59:21 dimik systemd[1]: Started LSB: Starts elasticsearch.
  </code></pre>