There may have many ways to install Java on Ubuntu. However, in this example I’ll show the manual way which is download the JDK from the official website.

There are few steps here:

Extract it and move to /opt directory.

1
2
$ tar -zxvf jdk_<version>.tar.gz
$ sudo mv jdk_<version> /opt/ # NOTE: /opt is a directory like `Program file` in Windows

Add Java to Environment Variable.

1
2
3
4
5
$ vi ~/.bash_profile
# Append this two lines:
# export JAVA_HOME='/opt/jdk_<version>/bin'
# export PATH=$PATH:${JAVA_HOME}
# Press :wq to save it

Activate the bash profile for immediate effect.

1
$ source ~/.bash_profile

Re-open terminal (i.e. CTRL + ALT + T for shortcut)

1
$ java -showversion

It should work. Have fun :)