On an Ubuntu or Debian VPS, install Java with APT by updating package indexes, choosing a runtime (JRE) or development kit (JDK), verifying the binaries, and selecting the active version if more than one is installed. The safest package is usually the distribution default; use a versioned OpenJDK package only when your application requires a specific Java line.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
What you need before installing Java
You need SSH access to the VPS, an account allowed to run sudo, and a supported Ubuntu or Debian installation. Java packages are built for particular distribution releases and CPU architectures, so identify those details before hard-coding a package name in a script.
As an Amazon Associate I earn from qualifying purchases.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Identify the distribution and release
Run:
cat /etc/os-release
Read the ID, VERSION_ID, and release-name fields. Ubuntu and Debian use related package tools but do not always expose the same default Java version. Debian’s documented default also varies by release and architecture.
Check the VPS architecture
APT normally selects the correct architecture automatically, but an architecture mismatch can make a package appear unavailable. Check both the Debian package architecture and the kernel’s machine type:
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
dpkg --print-architecture
uname -m
Keep the output with your deployment notes, especially if you are automating installation across VPS instances with different CPU types.
See what your repositories provide
Before selecting a version, inspect the repository metadata:
apt-cache policy default-jdk
apt-cache depends default-jdk
apt search openjdk
The Debian Project notes that the default-jdk dependency can change with the release and architecture. These commands show which package candidate your configured repositories currently offer instead of assuming that a version available on one VPS exists on another.
Choose the right Java package
Your choice depends on whether the VPS only runs compiled Java software or must compile source code and run build tools. A Java runtime and a development kit are not interchangeable when the javac compiler is required.
| VPS requirement | Package pattern | What it provides |
|---|---|---|
| Run an existing Java application | default-jre or openjdk-<version>-jre |
Runtime components for executing Java programs, with a smaller dependency footprint than a JDK |
| Compile Java or run build tools | default-jdk or openjdk-<version>-jdk |
The runtime plus javac and development tooling |
| Run a service that has no graphical requirement | A repository-provided headless JRE or JDK variant | Java without graphical interfaces; Debian defines headless packages this way |
| Support an application locked to one Java major version | openjdk-<version>-jre or openjdk-<version>-jdk |
APT-managed updates while remaining on the selected major-version line |
When default-jre is enough
Install the default runtime when the application is already compiled and only needs the java launcher. This is the normal choice for a VPS that runs a packaged server, worker, or service and does not compile code during deployment.
When you need default-jdk
Choose the default JDK when you compile source on the server, run a build system that invokes javac, or use Java tools that are not included in a runtime-only installation. It is also the practical choice when you do not have a requirement for a particular major version and want the release’s supported default.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →When to use a versioned package
Use a versioned package when the application documentation, framework, or deployment policy requires a specific Java line. The general form is openjdk-<version>-jdk for development or openjdk-<version>-jre for runtime-only use. Substitute a version that your VPS repositories actually list.
Ubuntu and Debian defaults are not identical
Do not copy a package name from one distribution release into another without checking APT. Ubuntu’s current documentation says the Ubuntu Archive provides supported OpenJDK LTS packages. It identifies OpenJDK 17 and 21 as TCK-certified on Ubuntu 24.04 LTS and uses OpenJDK 21 in its latest-LTS installation example.
| System information | Documented default or guidance | How to verify on the VPS |
|---|---|---|
| Ubuntu 24.04 LTS | Ubuntu documents supported OpenJDK LTS packages; OpenJDK 17 and 21 are TCK-certified, with openjdk-21-jdk used as the current latest-LTS example. |
apt search openjdk and apt-cache policy default-jdk |
| Debian 12 (Bookworm) | Debian records OpenJDK 17 as the default for Bookworm. | apt-cache policy default-jdk |
| Debian 11 (Bullseye) | Debian records OpenJDK 11 as the default for Bullseye. | apt-cache policy default-jdk |
Debian warns that defaults can differ by architecture. Treat the table as release guidance, not a guarantee that every architecture or repository configuration exposes the same candidate.
Install Java over SSH with APT
1. Refresh the package index
APT uses a local index of packages and versions. Refresh it before installing anything:
sudo apt update
Ubuntu’s server documentation identifies APT as the recommended command-line tool for Debian packages and uses this command to update the local package index. A successful run ends with repository metadata being read without an error. If APT reports a repository failure, resolve that first; installing from an incomplete index can produce an “unable to locate package” result.
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
2. Install a runtime-only environment
For a VPS that only runs an existing Java application, install:
sudo apt install default-jre
Ubuntu documents default-jre as the current OpenJDK runtime package for most situations. APT resolves the release-appropriate implementation and its dependencies. Review the proposed package list and confirm when prompted.
3. Install the development kit
For compilation or build tooling, run:
sudo apt install default-jdk
This installs the distribution’s default JDK rather than asking you to select a manually downloaded archive. It should provide both the java launcher and javac compiler.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problems4. Install a specific OpenJDK line
If your application requires Java 21 and the package is available in the configured repositories, Ubuntu’s current example is:
sudo apt install openjdk-21-jdk
For another supported major version, replace 21 with the version shown by apt search openjdk:
sudo apt install openjdk-<version>-jdk
Use the corresponding -jre suffix when you need only the runtime. Do not assume that a versioned package exists merely because the name follows this pattern; availability is determined by the VPS release, enabled repositories, and architecture.
5. Prefer headless packages for non-GUI services when available
A typical daemon, API server, or background worker has no need for graphical interfaces. Debian’s headless Java packages omit those interfaces, which can reduce unnecessary dependencies. Discover the exact variant in your repositories rather than guessing its name:
Free tools Windows power users keep installed
One-click scans. No signup required.
apt search openjdk | grep -i headless
Install the matching headless JRE or JDK package shown for your release. A Java application that creates windows, renders desktop graphics, or otherwise depends on GUI libraries may require the non-headless package instead.
Verify the installation
Check the runtime immediately after APT finishes:
java -version
Ubuntu explicitly uses java -version as its post-install check. The output should show a Java version and vendor/build information, followed by a normal shell prompt.
If you installed a JDK, verify the compiler separately:
javac -version
Seeing a version from both commands confirms that the launcher and compiler are available to your shell. A runtime-only installation is expected to provide java without javac.
Recommended Free Tools
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
Confirm which executable is active
When diagnosing multiple installations, inspect the command path:
command -v java
readlink -f "$(command -v java)"
This shows whether the shell is using the alternatives-managed executable and which installed Java tree it ultimately reaches.
Switch between multiple Java installations
Installing a second major version does not mean every application automatically uses it. Debian documents update-java-alternatives for switching Java environments and notes that it can update the alternatives together instead of managing each command separately.
List the registered Java environments
sudo update-java-alternatives --list
The output contains the names of Java environments registered with the alternatives system. Copy the exact name you want to activate.
Select one environment
sudo update-java-alternatives --set <environment-name>
Replace <environment-name> with the entry returned by the list command. Verify the result again:
java -version
javac -version
If you need to adjust one command rather than the complete environment, the alternatives interface can also present an interactive selection for an individual link:
sudo update-alternatives --config java
sudo update-alternatives --config javac
Choose the path corresponding to the same Java installation for both commands when you are using a JDK. Do not replace /usr/bin/java by hand; manual replacement bypasses the package manager’s alternatives records and makes future upgrades harder to reason about.
Use APT-managed Java in deployment scripts
A repeatable script should discover the operating system, refresh indexes, install the package required by the workload, and verify the result. Keep the package choice explicit so a runtime-only service does not unexpectedly receive compiler tooling.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Runtime-only example
set -e
sudo apt update
sudo apt install -y default-jre
java -version
The -y flag accepts APT’s confirmation prompt, which is useful in non-interactive provisioning. Keep set -e (or the equivalent error handling in your automation system) so a failed update does not silently continue to installation.
Build-server example
set -e
sudo apt update
sudo apt install -y default-jdk
java -version
javac -version
For a pinned major version, replace default-jdk with the versioned package that your repository inspection confirmed. Re-check package availability whenever the script targets a new distribution release or architecture.
Keep package sources consistent
Ubuntu and Debian repository packages receive distribution-managed updates. Mixing an APT installation with a manually extracted Java archive complicates upgrades, executable selection, and alternatives management. If you standardize on APT, keep the Java installation under APT and make version changes through package and alternatives commands.
Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
Troubleshoot common installation failures
“Unable to locate package”
This message usually means one of four things: the package index is stale, the repository component is unavailable, the requested version is not built for the VPS architecture, or the package name does not exist for that release.
- Refresh metadata:
sudo apt update. - Check the candidate and repository origin:
apt-cache policy default-jdk. - Search the names actually available:
apt search openjdk. - Confirm the architecture with
dpkg --print-architecture. - Install the release’s available package name instead of forcing a package copied from another system.
If apt update itself reports a repository or signature error, fix that repository configuration before retrying the Java installation.
java works but javac is missing
You installed a JRE rather than a JDK. Install the matching development package:
sudo apt install default-jdk
If you intentionally use a versioned runtime, install the corresponding versioned JDK instead, then verify both commands.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The wrong Java version runs
Multiple installations are present, but the alternatives selection still points to another one. List environments, select the desired entry with update-java-alternatives, and verify java -version and javac -version. Check the resolved path with readlink -f if the output remains unexpected.
A graphical Java application fails on the VPS
A headless package omits graphical interfaces by design. If the application needs desktop or rendering libraries, install the regular JRE or JDK variant available for your distribution. For an ordinary server daemon, retain the headless choice and investigate the application’s actual dependency requirements rather than adding GUI libraries preemptively.
A package was installed outside APT
Manually extracted archives and APT packages can create competing executables and update paths. Decide which source should own Java, remove or isolate the competing installation according to its vendor’s procedure, and then use the alternatives system to select the remaining APT-managed environment. Avoid editing system symlinks directly.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Operational checks after installation
Before handing the VPS to an application, confirm all of the following:
Recommended Free Tools
- The distribution release and architecture match the package choice.
sudo apt updatecompletes without repository errors.- The selected package is intentional: JRE for execution, JDK for compilation, or a headless variant for a non-GUI service.
java -versionreports the required major version.javac -versionsucceeds when the workload compiles code.- If multiple Java installations exist, the alternatives selection points to the intended environment.
- The application’s service configuration invokes the same Java installation you verified from the shell.
Once these checks pass, the VPS has a package-managed Java installation that can receive the normal updates for its Ubuntu or Debian release without manually replacing system executables.
Plan the package choice for upgrades
The default-jre and default-jdk names follow the distribution’s selected default. That makes them convenient for a general-purpose server, but the underlying major version can change when you move to a different distribution release. If an application is certified only against one Java line, use the matching versioned package and record that requirement in your deployment configuration.
A versioned OpenJDK package still receives updates through APT while staying on its selected major-version line. Before upgrading the VPS or rebuilding it on a new architecture, repeat apt-cache policy and apt search openjdk; package availability is a property of the configured release and architecture, not just the package name.
Best Value
Quick decision workflow
- Identify the Ubuntu or Debian release and CPU architecture.
- Run
sudo apt updateand make sure repositories complete without errors. - Choose
default-jrefor an application that only runs Java bytecode. - Choose
default-jdkwhen compilation or build tools are needed. - Choose a versioned or headless package only after confirming its exact name with APT.
- Verify
java -version, and verifyjavac -versionfor a JDK. - Use the alternatives system if more than one Java environment is installed.
This sequence keeps installation reproducible while leaving the package manager responsible for dependencies, updates, and executable selection.
Free tools Windows power users keep installed
One-click scans. No signup required.
Frequently Asked Questions
Should I install a JRE or a JDK on a VPS?
Install default-jre when the server only runs an already compiled Java application. Install default-jdk when it compiles source, runs build tools, or needs javac and other development utilities. A JRE is not a substitute for a JDK when compilation is required.
What is the safest package if I do not need a specific Java version?
Use the distribution default: sudo apt install default-jre for runtime-only use or sudo apt install default-jdk for development. The default package follows the Ubuntu or Debian release’s supported choice, so inspect it with apt-cache policy default-jdk when automating across releases.
How do I install Java 21 specifically?
First confirm that your repositories list it with apt search openjdk. If available, install sudo apt install openjdk-21-jdk, or use the corresponding openjdk-21-jre package for runtime-only use. Do not assume the package exists on every release or architecture.
Which Java version is default on Debian?
Debian documents OpenJDK 17 as the default for Debian 12 (Bookworm) and OpenJDK 11 as the default for Debian 11 (Bullseye). Defaults can vary by architecture, so verify the actual candidate on the VPS with apt-cache policy default-jdk.
Are headless Java packages suitable for server applications?
Yes, when the application has no graphical requirement. Debian defines headless packages as omitting graphical interfaces, making them appropriate for many daemons, workers, and API services. A desktop or rendering application may require the regular JRE or JDK instead.
Why does APT say it cannot locate an OpenJDK package?
Refresh the index with sudo apt update, then inspect available names using apt search openjdk. Also check repository errors, the configured release, and the architecture from dpkg --print-architecture. The requested version may not be built for that VPS or may not exist for that release.
How do I make one of several installed Java versions active?
List registered environments with sudo update-java-alternatives --list, select one with sudo update-java-alternatives --set <environment-name>, and verify both java -version and javac -version. For one command at a time, use update-alternatives --config.
Can I mix an APT Java package with a manually extracted archive?
You can, but competing installations complicate upgrades, executable paths, and alternatives management. Keep one source responsible for Java when possible. If an archive is already installed, remove or isolate it according to its vendor’s procedure and use the alternatives system rather than editing /usr/bin/java manually.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Do I need to run apt update every time I run a Java install command?
Run sudo apt update before installation whenever the local package index may be stale, especially on a new VPS or in a provisioning script. It lets APT see current package candidates and helps distinguish a missing package from a repository or metadata problem.
The Bottom Line
Install Java on an Ubuntu or Debian VPS by running sudo apt update, choosing default-jre or default-jdk for the workload, and verifying with java -version. Use a versioned or headless OpenJDK package only after confirming its availability, and manage multiple installations with the alternatives system.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




