Before I start, please note that the JDK also contains the JRE within it.
To install the openJDK JDK and JRE 8 use (replace
8 with the version you want, such as
sudo apt-get install openjdk-8-jdk
If you instead want to install the official Oracle JDK and JRE and definitely want to install through
apt-get then do (you can replace the
8 with other versions such as
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Or if you want to install the official Oracle Java version manually:
Go here and click the download button:
Select the Accept License Agreement radio button (once you have read the license agreement).
Select the file you want to download, if you are running on a 32-bit machine click
[javaversion] replaced with the Java version, such as
8u60), if 64-bit then
Launch Terminal (CTRL + ALT + T), then
cd to the directory where you downloaded the file to (probably
~/Downloads), and run
tar -xvf /path/to/file.tar.gz to unpack that archive into the directory the file is in, you may then move that unpacked archive into a desired location, such as the
/opt directory (storing executable files in your home directory is a security risk).
Once you have done the above you may delete the original
.tar.gz file, and then open up your
~/.bashrc file in a desired file editor such as
vim, I will be using
vim in this example (install it with
sudo apt-get install vim if it is not already installed). So run
vim ~/.bashrc and then insert two new lines at the bottom of the file which read (that is with
/path/to/unpacked/archive replaced with the path to the archive you just unpacked):
Either restart Terminal or run
source ~/.bashrc to start using the new
Note: With this method you will have to carry on doing this every time there is a new Java version released which it will not notify you about.