After various incorrect SO answers, I’ve found the right solution for ubuntu 16.04 LTS.
cd ~
cat .profile
edit .profile file and add these lines
PATH=$PATH:/home/user/android-sdk/platform-tools:/home/user/java/jdk1.8.0_121/bin
export JAVA_HOME=/home/user/java/jdk1.8.0_121
export STUDIO_JDK=$JAVA_HOME
export JDK_HOME=$JAVA_HOME
Then Ctrl+X and save
After rebooting my machine (closing the terminal didn’t work, I don’t know if closing session will be enough, but anyway my machine boots in 15 seconds so rebooting is quite fast :P) I can work with the new path. To check it:
java -version
should return the correct version of Java installed