To check the current version, run

java -version

To install Java on our PC, we have two alternatives, via PPA:

*sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

For Java 8:

sudo apt-get install oracle-java8-installer

For Java 7:

sudo apt-get install oracle-java7-installer

or manually:

  1. Check the architecture of our Linux operating system.
  1. Check if we have any version of Java: francisco@francisco-Aspire-V5-122:~$ java -version java version "1.7.0_79" OpenJDK Runtime Environment (IcedTea 2.5.6) (7u79-2.5.6-0ubuntu1.14.04.1) OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
  1. Uninstall and remove OpenJDK/JRE from the system. *francisco@francisco-Aspire-V5-122:~$ sudo apt-get purge openjdk-\
  1. Download the package from its website.
  1. Extract the file: francisco@francisco-Aspire-V5-122:~$ tar xvfz jdk-8u60-linux-x64.tar.gz
  1. Create the directory where Oracle JDK/JRE will be installed francisco@francisco-Aspire-V5-122:~$ sudo mkdir /usr/local/jdk francisco@francisco-Aspire-V5-122:~$ ls /usr/local/ bin etc games include jdk lib man sbin share src
  1. Copy the binaries from the file we extracted into the installation directory francisco@francisco-Aspire-V5-122:~$ sudo cp -rfv jdk1.8.0_60/ /usr/local/jdk/
  1. Grant execution permissions to all system users on the Java installation directory. francisco@francisco-Aspire-V5-122:~$ sudo chmod -R a+x /usr/local/jdk/
  1. Update the PATH by adding the new environment variables to the system; we use a text editor to modify the /etc/profile file and add the new environment variables at the end of the file: francisco@francisco-Aspire-V5-122:~$ sudo nano /etc/profile # Al final del archivo agrego las nuevas variables de entorno JAVA_HOME=/usr/local/jdk/jdk1.8.0_60 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export JAVA_HOME export PATH
  1. Notify the Linux system where our Oracle Java JDK/JRE is installed francisco@francisco-Aspire-V5-122:~/Downloads$ sudo update-alternatives --install "/usr/local/java" "java" "/usr/local/jdk/jdk1.8.0_60/bin/java" 1update-alternatives: using /usr/local/jdk/jdk1.8.0_60/bin/java to provide /usr/local/java (java) in auto modefrancisco@francisco-Aspire-V5-122:~/Downloads$ sudo update-alternatives --install "/usr/local/javac" "javac" "/usr/local/jdk/jdk1.8.0_60/bin/javac" 1update-alternatives: using /usr/local/jdk/jdk1.8.0_60/bin/javac to provide /usr/local/javac (javac) in auto modefrancisco@francisco-Aspire-V5-122:~/Downloads$ sudo update-alternatives --install "/usr/local/javaws" "javaws" "/usr/local/jdk/jdk1.8.0_60/bin/javaws" 1update-alternatives: using /usr/local/jdk/jdk1.8.0_60/bin/javaws to provide /usr/local/javaws (javaws) in auto mode
  1. Configure Oracle Java JDK/JRE as the default Java to use: francisco@francisco-Aspire-V5-122:~/Downloads$ sudo update-alternatives --set java /usr/local/jdk/jdk1.8.0_60/bin/javafrancisco@francisco-Aspire-V5-122:~/Downloads$ sudo update-alternatives --set javac /usr/local/jdk/jdk1.8.0_60/bin/javacfrancisco@francisco-Aspire-V5-122:~/Downloads$ sudo update-alternatives --set javaws /usr/local/jdk/jdk1.8.0_60/bin/javaws
  1. Finally, all that's left is to reload the PATH and verify if the installation was completed successfully: francisco@francisco-Aspire-V5-122:~/Downloads$ . /etc/profile francisco@francisco-Aspire-V5-122:~/Downloads$ java -version java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) francisco@francisco-Aspire-V5-122:~/Downloads$ javac -version javac 1.8.0_60