Problem to install logstash using deb file on ubuntu 16.0.4

and finally,
I found my problem! on this result of installation:

elk@elk:~$ sudo dpkg --install logstash-6.2.2.deb
Selecting previously unselected package logstash.
(Reading database ... 116903 files and directories currently installed.)
Preparing to unpack logstash-6.2.2.deb ...
Unpacking logstash (1:6.2.2-1) ...
Setting up logstash (1:6.2.2-1) ...
Using provided startup.options file: /etc/logstash/startup.options
/usr/share/logstash/vendor/jruby/bin/jruby: line 401: /usr/bin/java: No such file or directory
Unable to install system startup script for Logstash.
chmod: cannot access '/etc/default/logstash': No such file or directory
dpkg: error processing package logstash (--install):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 logstash

this problem and some else basically for java! you can change java path on /etc/logstash/startup.options and run installation command again, it will be ok but some problem will arise!

My Solution:
I have installed java manually in /usr/local/java/.... but logstash by default read /usr/bin/java to use java.
to do it I use this guide to install java and run logstash installation command again. it works well.

wget http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-i586.tar.gz
sudo mkdir /usr/lib/jvm
cd /usr/lib/jvm
sudo tar -xvzf ~/Downloads/jdk-8u151-linux-x64.tar.gz
vi /etc/environment

Add this line to environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_151/bin:/usr/lib/jvm/jdk1.8.0_151/db/bin:/usr/lib/jvm/jdk1.8.0_151/jre/bin"
J2SDKDIR="/usr/lib/jvm/jdk1.8.0_151"
J2REDIR="/usr/lib/jvm/jdk1.8.0_151/jre"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_151"
DERBY_HOME="/usr/lib/jvm/jdk1.8.0_151/db"

then save it and close. after that run this commands:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_151/bin/java" 0 
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_151/bin/javac" 0 
sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_151/bin/java 
sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_151/bin/javac


reboot