After various incorrect SO answers, I’ve found the right solution for ubuntu 16.04 LTS.
edit .profile file and add these lines
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:
should return the correct version of Java installed