Install OpenJDK on Ubuntu
1. Which version should you install?
OpenJDK is an open source code of the Java (Java Development Kit) maintained and developed by Oracle and the community. OpenJDK has similar features as Oracle JDK.
You may find them interesting:
Until 2020, Oracle has released Java 13, but there are only a few long-term supported versions, Java 8, 11, 13. Therefore, you can use one of these versions rather than other versions which are no longer supported by Oracle and there are very few users nowadays.
Java 8, despite being released in March 2014, still has a large number of users today, due to its long-term Oracle support, and its stability.
2. Installing OpenJDK 8
Installing OpenJDK 8 is extremely simple. On Ubuntu, open Terminal and execute some commands as follows:
sudo apt update
With OpenJDK version 8, 9:
# Install OpenJDK 8:
sudo apt install openjdk-8-jdk
# Install OpenJDK 9:
sudo apt install openjdk-9-jdk
Then check the result of the installation:
java -version
3. Installing OpenJDK 11
Installing OpenJDK 11 is a bit more complicated than OpenJDK 8 because you need to download and install it.
Download OpenJDK 11:
wget https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz
Next, extract the file that you have just downloaded in the previous step.
tar xzvf openjdk-11_linux-x64_bin.tar.gz
After that, move the folder you have got after extracting to /usr/lib/jvm folder.
# Create directory:
sudo mkdir /usr/lib/jvm
# Move:
sudo mv jdk-11 /usr/lib/jvm/openjdk-11-manual-installation/
Finally, you need to make sure that the java & javac commands are pointing to the right location.
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/openjdk-11-manual-installation/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/openjdk-11-manual-installation/bin/javac 1
# keytool (Optional)
sudo update-alternatives --install /usr/bin/keytool keytool /usr/lib/jvm/openjdk-11-manual-installation/bin/keytool 1
Now check what you installed:
java -version
4. Installing OpenJDK 13
First of all, you need an address to download OpenJDK 13:
You will have an address to download OpenJDK similar below:
https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_linux-x64_bin.tar.gz
Next, use the command to download it:
wget https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_linux-x64_bin.tar.gz
After that, extract the file you have just downloaded in the previous step.
tar xzvf openjdk-13.0.2_linux-x64_bin.tar.gz
Then move the folder you have got after extracting to /usr/lib/jvm folder.
# Create directory:
sudo mkdir /usr/lib/jvm
# Move:
sudo mv jdk-13.0.2 /usr/lib/jvm/openjdk-13-manual-installation/
Finally, you need to make sure that the java & javac commands are pointing to the right location.
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/openjdk-13-manual-installation/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/openjdk-13-manual-installation/bin/javac 1
# keytool (Optional):
sudo update-alternatives --install /usr/bin/keytool keytool /usr/lib/jvm/openjdk-13-manual-installation/bin/keytool 1
Let's check the installation result:
java -version
5. Set Default Version
If you have multiple versions of JDK installed on your operating system, you need to specify a default version.
Check to see which versions of JDK are installed on your computer:
sudo update-alternatives --config java
You will get similar results as follows, enter 1 (or 2, ...) to select the default version you would like to use.
sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0
/usr/lib/jvm/openjdk-11-manual-installation/bin/java1111 auto mode 1
/usr/lib/jvm/openjdk-11-manual-installation/bin/java1111 manual mode 2
/usr/lib/jvm/openjdk-13-manual-installation/bin/java1081 manual mode Press to keep the current choice[*], or type selection number:
Finally, set the JAVA_HOME environment variable:
export JAVA_HOME=/usr/lib/jvm/openjdk-13-manual-installation/bin/java
Now check the result of setting the environment variable:
echo $JAVA_HOME
Java Basic
- Customize java compiler processing your Annotation (Annotation Processing Tool)
- Java Programming for team using Eclipse and SVN
- Java WeakReference Tutorial with Examples
- Java PhantomReference Tutorial with Examples
- Java Compression and Decompression Tutorial with Examples
- Configuring Eclipse to use the JDK instead of JRE
- Java String.format() and printf() methods
- Syntax and new features in Java 8
- Java Regular Expressions Tutorial with Examples
- Java Multithreading Programming Tutorial with Examples
- JDBC Driver Libraries for different types of database in Java
- Java JDBC Tutorial with Examples
- Get the values of the columns automatically increment when Insert a record using JDBC
- Java Stream Tutorial with Examples
- Java Functional Interface Tutorial with Examples
- Introduction to the Raspberry Pi
- Java Predicate Tutorial with Examples
- Abstract class and Interface in Java
- Access modifiers in Java
- Java Enums Tutorial with Examples
- Java Annotations Tutorial with Examples
- Comparing and Sorting in Java
- Java String, StringBuffer and StringBuilder Tutorial with Examples
- Java Exception Handling Tutorial with Examples
- Java Generics Tutorial with Examples
- Manipulating files and directories in Java
- Java BiPredicate Tutorial with Examples
- Java Consumer Tutorial with Examples
- Java BiConsumer Tutorial with Examples
- What is needed to get started with Java?
- History of Java and the difference between Oracle JDK and OpenJDK
- Install Java on Windows
- Install Java on Ubuntu
- Install OpenJDK on Ubuntu
- Install Eclipse
- Install Eclipse on Ubuntu
- Quick Learning Java for beginners
- History of bits and bytes in computer science
- Data Types in java
- Bitwise Operations
- if else statement in java
- Switch Statement in Java
- Loops in Java
- Arrays in Java
- JDK Javadoc in CHM format
- Inheritance and polymorphism in Java
- Java Function Tutorial with Examples
- Java BiFunction Tutorial with Examples
- Example of Java encoding and decoding using Apache Base64
- Java Reflection Tutorial with Examples
- Java remote method invocation - Java RMI Tutorial with Examples
- Java Socket Programming Tutorial with Examples
- Which Platform Should You Choose for Developing Java Desktop Applications?
- Java Commons IO Tutorial with Examples
- Java Commons Email Tutorial with Examples
- Java Commons Logging Tutorial with Examples
- Understanding Java System.identityHashCode, Object.hashCode and Object.equals
- Java SoftReference Tutorial with Examples
- Java Supplier Tutorial with Examples
- Java Aspect Oriented Programming with AspectJ (AOP)
Show More
- Java Servlet/Jsp Tutorials
- Java Collections Framework Tutorials
- Java API for HTML & XML
- Java IO Tutorials
- Java Date Time Tutorials
- Spring Boot Tutorials
- Maven Tutorials
- Gradle Tutorials
- Java Web Services Tutorials
- Java SWT Tutorials
- JavaFX Tutorials
- Java Oracle ADF Tutorials
- Struts2 Framework Tutorials
- Spring Cloud Tutorials