Java is the language that refuses to die and your machine needs a runtime and a compiler if you plan to write or run Java programs. This guide shows how to install OpenJDK on Ubuntu with the apt package manager, verify the runtime and compiler, and manage multiple JDK versions without turning your system into a confusion shrine.
First make sure apt knows what is new and exciting. Run the update command so the package index is up to date. You can also upgrade everything if you want to live dangerously.
sudo apt update
sudo apt upgrade -y
For most people the default JDK is the easiest option. If you need a specific LTS release pick openjdk-11-jdk or openjdk-17-jdk depending on your project. The package manager will fetch the runtime and the compiler so you do not have to be a package whisperer.
sudo apt install default-jdk
# or for a specific version
sudo apt install openjdk-11-jdk
After installation confirm both the runtime and the compiler are present. Mismatched versions are the leading cause of build confusion and dramatic error messages.
java -version
javac -version
If the versions in the output look sane then congrats. If not you may have multiple JDKs installed which leads us to the next delightful topic.
Ubuntu provides the update alternatives tool to pick which java and javac are the system defaults. It is a menu driven selection so you do not need to edit symlinks while holding your breath.
sudo update-alternatives --config java
sudo update-alternatives --config javac
Choose the number that corresponds to the version you want. Repeat for both java and javac when necessary to avoid build time surprises.
If a JDK is causing trouble or you simply want less clutter remove it with apt and then clean up leftover packages.
sudo apt remove openjdk-11-jdk
sudo apt autoremove
apt search openjdk
to see what versions your Ubuntu release offersFollowing these steps will give you a working Java runtime and compiler on Ubuntu ready for development or production deployment. It is not rocket science, but it is precise science. Keep your package list fresh, pick the JDK that matches your project, and use update alternatives when the universe offers choices. Now go write something that will print Hello World and then promptly crash in a useful way.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.