Java is one of the most popular programming platforms used by developers around the world. Whether you want to run Java applications or develop them yourself, having Java installed on your Ubuntu system is essential.
In this beginner-friendly guide, I’ll walk you through the steps to install different versions of Java on your Ubuntu 22.04 LTS system. We will cover installing both the Java Runtime Environment (JRE) to run Java programs and the full Java Development Kit (JDK) to compile Java code.
Before installing Java, make sure your Ubuntu system is fully updated by running:
sudo apt update && sudo apt upgrade
This will fetch the latest updates from the Ubuntu repositories and prep your system.
When installing Java on Ubuntu, you have the option of using the free and open-source OpenJDK or the official Oracle Java Development Kit. Here are some key differences:
Licensing:
OpenJDK is licensed under GPL and can be freely used in commercial applications
Oracle JDK is proprietary and requires a commercial license for business use
Performance:
OpenJDK and Oracle JDK generally have similar runtime performance
Some benchmarks show Oracle JDK slightly faster in certain workloads
Features:
OpenJDK provides all core Java features and keeps up with Oracle’s releases
Some advanced management and monitoring tools only available with Oracle JDK
Support:
OpenJDK is community-supported with Ubuntu forums/chat available
Oracle provides official support, updates and patches for Oracle JDK
So in summary, OpenJDK works great for most developer needs and Ubuntu systems. But certain commercial software products may mandate using Oracle Java. For proprietary applications, the paid Oracle JDK support may also be preferred.
Hope this gives you the context to decide which Java distribution better meets your needs!
The easiest way to install Java is via Ubuntu’s default repositories which contain OpenJDK – the open-source version of Java.
To install OpenJDK 11, run:
sudo apt install default-jre default-jdk
This will install both the JRE and JDK. To confirm, check their versions:
java -version
javac -version
If you require the official Oracle Java JDK, you’ll need to manually install it.
First, add Oracle’s PPA to apt:
sudo add-apt-repository ppa:linuxuprising/java
Then update apt and install the latest Java JDK 11:
sudo apt update
sudo apt install oracle-java11-installer
Once done, you can check the installed version:
java -version
And to set it as the default Java:
sudo update-alternatives --config java
If you need an older Java version like Java 8 or 17, run:
sudo apt install oracle-java8-installer
sudo apt install oracle-java17-installer
Again check the version with java -version
and update alternatives if needed.
No matter whetever the Java version you install. You may need to set the env variable. Many Java apps and servers require the JAVA_HOME
env variable set to function properly.
To set this permanently on Ubuntu, edit /etc/environment
and add:
nano /etc/environment
OpenJDK
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
Oracle JDK
JAVA_HOME="/usr/lib/jvm/java-11-oracle"
Just remember to replace the path with where your preferred Java version is installed.
After saving the changes, run source /etc/environment
to reload the file. Java should now be fully up and running!
Installing Java runtime and development kits on Ubuntu is super easy whether you want to use OpenJDK or Oracle’s official distribution.
Now you can install IntelliJ, Eclipse, or other Java IDEs to start developing your own applications on Ubuntu!
Let me know in the comments if you have any issues getting Java running on your system.
We hope this post helps learning how to install Java on Ubuntu Linux. Thanks for reading this tutorial post. Visit our website thesecmaster.com and social media page on Facebook, LinkedIn, Twitter, Telegram, Tumblr, Medium & Instagram, and subscribe to receive updates like this.
You may also like these articles:
Arun KL is a cybersecurity professional with 15+ years of experience in IT infrastructure, cloud security, vulnerability management, Penetration Testing, security operations, and incident response. He is adept at designing and implementing robust security solutions to safeguard systems and data. Arun holds multiple industry certifications including CCNA, CCNA Security, RHCE, CEH, and AWS Security.
“Knowledge Arsenal: Empowering Your Security Journey through Continuous Learning”
"Cybersecurity All-in-One For Dummies" offers a comprehensive guide to securing personal and business digital assets from cyber threats, with actionable insights from industry experts.
BurpGPT is a cutting-edge Burp Suite extension that harnesses the power of OpenAI's language models to revolutionize web application security testing. With customizable prompts and advanced AI capabilities, BurpGPT enables security professionals to uncover bespoke vulnerabilities, streamline assessments, and stay ahead of evolving threats.
PentestGPT, developed by Gelei Deng and team, revolutionizes penetration testing by harnessing AI power. Leveraging OpenAI's GPT-4, it automates and streamlines the process, making it efficient and accessible. With advanced features and interactive guidance, PentestGPT empowers testers to identify vulnerabilities effectively, representing a significant leap in cybersecurity.
Tenable BurpGPT is a powerful Burp Suite extension that leverages OpenAI's advanced language models to analyze HTTP traffic and identify potential security risks. By automating vulnerability detection and providing AI-generated insights, BurpGPT dramatically reduces manual testing efforts for security researchers, developers, and pentesters.
Microsoft Security Copilot is a revolutionary AI-powered security solution that empowers cybersecurity professionals to identify and address potential breaches effectively. By harnessing advanced technologies like OpenAI's GPT-4 and Microsoft's extensive threat intelligence, Security Copilot streamlines threat detection and response, enabling defenders to operate at machine speed and scale.