UPDATE : non-root installation below
I advise you not to install packages manually on an ubuntu system if you already have a (semi-official) repository that can solve your problem. Also, use the Oracle JDK for development to avoid (very sporadic) compatibility issues (I tried many years ago, this is definitely better now).
Add the webupd8 repository to your system:
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update
Install your preferred jdk version (versions from java-6 to java-9 are available):
sudo apt-get install oracle-java8-installer
You can also install several versions of jdk, mix openjdk and oracle versions. Then you can use the update-java-alternatives command to switch between the installed version:
# list available jdk update-java-alternatives --list
Requirements
If you get add-apt-repository: command not found , be sure to set software-properties-common :
sudo apt-get install software-properties-common
If you are using an older version of Ubuntu:
sudo apt-get install python-software-properties
Install JDK without root privileges
If you do not have administrator rights on your target machine, try using sdkman to install the certified zulu openjdk:
curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install java
NOTE. sdkman also allows you to install the official Oracle JDK, although this is not the default option. View available versions with:
sdk ls java
Install the selected version using
sdk install java <version>
For example:
sdk install java 9.0.1-oracle
Team Glossary
sudo <command> [command_arguments] : run the command with superuser privilege.
add-apt-repository <PPA_id> : Ubuntu (like all Debian derivatives and, generally speaking, every Linux distribution) has a main package repository that handles things like package dependencies and updates. In Ubuntu, you can expand the main repository using PPA (Personal Package Archive), which usually contains packages that are not available on the system (for example, oracle jdk) or updated versions of available (for example: LibreOffice 5 in LTS is available only through this PPA ).
apt-get [install|update|upgrade|purge|...] : it is a "command line package handler used to control the status of each repository in the system (installation / update / update can be viewed as a change in the current state of the repository).
In our case: using the sudo add-apt-repository ppa:webupd8team/java we tell the system that the next repository update should also receive package information from the webupd8 repository.
With sudo apt-get update we actually update the system repository (all these operations require superuser privileges, so we add sudo to the commands).
sudo apt-get install oracle-java8-installer
update-java-alternatives (a specific version of java alternative updates ): in Ubuntu, several packages provide the same functionality (surf the Internet, compile mail, edit a text file, or provide java / javac executables ...). In order for the system to select the tool of user favorites, taking into account a specific task, a mechanism is used using symbolic links in /etc/alternatives/ . Try updating jdk as above (switching between java 7 and java 8) and see how to change the output of this command:
ls -l /etc/alternatives/java*
In our case: sudo update-java-alternatives --set java-8-oracle update symbolic links under / etc / alternatives to point to java-8-oracle executables.
Additionally:
man <command> : start using the person to read the very well-written and detailed help of (almost) every shell command and its parameters (each command mentioned in this small answer, man page, try man update-java-alternatives ).
apt-cache search <search_key> : request APT cache to search for the package associated with the provided search key (may be the name of the package or some word in the package description)
apt-cache show <package> : provides APT information for a specific package (package version, installed or not, description).