Whereas Ubuntu doesn’t include a Java runtime preinstalled, it does come prepackaged with the flexibility to simply install Java with the apt
command.
There are a lot of other ways to put in Java on Ubuntu, but when all you want is the flexibility to run a Java program and even develop and compile some Java supply code, the apt-based set up path is the simplest one to observe.
How one can set up Java on Ubuntu
To rapidly setup and set up Java on Ubuntu, observe these steps:
- Confirm that you haven’t already put in Java
- Concern the
sudo apt replace
command - Set up Ubuntu’s default JDK with apt
- Run Java on the command line to check the set up
- Set JAVA_HOME globally for all Ubuntu customers
Do you even must setup Java on Ubuntu?
You don’t must setup Java on Ubuntu if somebody has already put in it for you.
Within the title of due diligence, first verify to see if Java is already put in by issuing the next command:
java - model Command 'java' not discovered, however might be put in with: sudo apt set up default-jdk sudo apt set up default-jre
If this command signifies that Java just isn’t discovered, then it’s not put in and you may proceed with the following steps.
Replace your package deal itemizing with apt replace
As with all Ubuntu software program installs, replace your Ubuntu package deal checklist with the latest info with the next command:
sudo apt-get replace Studying package deal lists... Executed Constructing dependency tree... Executed Studying state info... Executed All packages are updated.
Set up Java on ubuntu with apt
The complete Java suite contains the Java Runtime Setting (JRE), Java Digital Machine (JVM) and utilities to develop Java supply code.
The Java Improvement Equipment (JDK) gives all the things a consumer must run Java functions. Set up the JDK with the next command:
sudo apt set up default-jdk Establishing default-jdk-headless (2:1.11-72build2) ... Establishing openjdk-11-jdk:amd64 (11.0.15+10-0ubuntu0.22.04.1) ... utilizing /usr/lib/jvm/java-11-openjdk-amd64/bin/jconsole Establishing default-jdk (2:1.11-72build2) ...
Optionally set up the JRE as an alternative
The JDK moreover has a couple of further options packaged with it to facilitate software program improvement.
To put in Java on Ubuntu with none of the additional software program improvement instruments, you’ll be able to set up simply the JRE with the next command:
sudo apt set up default-jre Establishing default-jre (2:1.11-72build2) ...
Run Java in an Ubuntu terminal
To validate the profitable set up of Java on Ubuntu with apt, subject the next command:
java -version openjdk model "11.0.15" 2022-04-19 OpenJDK Runtime Setting (construct 11.0.15+10-Ubuntu-0ubuntu0.22.04.1) OpenJDK 64-Bit Server VM (construct 11.0.15+10-Ubuntu-0ubuntu0.22.04.1, combined mode, sharing)
If the java -version
command outputs details about the model of Java put in, together with details about the JVM and runtime surroundings, then you definitely efficiently put in Java on Ubuntu with apt.
Configure JAVA_HOME on Ubuntu
Configuring JAVA_HOME isn’t completely required, however many enterprise Java functions resembling Tomcat or Kafka question the JAVA_HOME listing once they startup and use that info at runtime, so it’s prudent to configure it.
The JAVA_HOME surroundings variable merely factors to the folder during which Java was put in.
Find your Java set up on Ubuntu
To search out out the place apt put in Java on Ubuntu, subject the next command and replica the placement supplied:
$ update-alternatives --config java There is just one different in hyperlink group java (offering /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Add JAVA_HOME to the surroundings
With the placement of the Java set up on the clipboard, open up the server’s surroundings file with Nano:
sudo nano /and so on/surroundings
Paste the JAVA_HOME project on the backside of the file:
JAVA_HOME="JAVA_HOME="/lib/jvm/java-11-openjdk-amd64/bin/java"
Then power the Ubuntu terminal to reload the surroundings configuration file:
supply /and so on/surroundings
You need to then be capable of echo the JAVA_HOME surroundings variable in an Ubuntu terminal window:
echo $JAVA_HOME /lib/jvm/java-11-openjdk-amd64/bin/java
Edit the surroundings file to set JAVA_HOME globally in Ubuntu.
Ubuntu Java set up instructions
As a fast overview, listed below are the entire instructions that had been issued on this tutorial to get Java put in on Ubuntu with apt:
-
sudo apt-get replace
-
sudo apt set up default-jdk
-
java -version
-
update-alternatives --config java
-
sudo nano /and so on/surroundings
-
supply /and so on/surroundings
-
echo $JAVA_HOME
And that’s how simple it’s to put in Java on Ubuntu with apt.