Set JAVA_HOME in Ubuntu without "install" the JDK

I've just downloaded and extracted the JDK archive, next moving it to my /opt directory. Inside IntelliJ, everything is working properly. I just point the path to the JDK in the settings. But I cannot issue java -version command... It says that I need to "install" Java... The question is: how can I set JAVA_HOME environment variable in Ubuntu, without actually "install" the JDK? Thanks!


Solution 1:

Add

export JAVA_HOME=/opt/path/to/jdk
export PATH=${PATH}:/opt/path/to/jdk/bin

to your ~/.bashrc.
After that, either reboot or apply these changes to your current shell with

source ~/.bashrc