Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

On an Ubuntu or Debian VPS, install Java with APT by updating the package index, choosing either a runtime (JRE) or development kit (JDK), installing the package, and checking the resulting binaries. A typical runtime-only installation is sudo apt update followed by sudo apt install default-jre. A server that compiles code or runs build tools needs sudo apt install default-jdk instead.

If the application requires a particular Java major version, use the versioned OpenJDK package available in the VPS repositories, such as sudo apt install openjdk-21-jdk. Verify with java -version, and use Debian’s alternatives tools when more than one Java installation is present.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What you need before installing

You need SSH access to the VPS, an account allowed to run commands with sudo, and a working network path to the configured Ubuntu or Debian repositories. APT installs distribution packages, so the package names and the Java version selected by a generic package such as default-jdk depend on the operating-system release and, in some cases, the CPU architecture.

Identify the distribution and release

Run this command over SSH:

cat /etc/os-release

Read the NAME, VERSION_ID, and release codename fields. Do not assume that instructions for one Ubuntu or Debian release apply unchanged to another; the release controls which OpenJDK packages are in the archive and which package a dependency such as default-jdk resolves to.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Check the architecture

Use both the Debian package architecture and the kernel’s machine name when diagnosing package availability:

dpkg --print-architecture
uname -m

Debian notes that the default-jdk dependency can vary by architecture and release. This check is especially important when automating installation across VPS images with different CPU types.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Refresh APT’s package index

Run:

sudo apt update

APT is the recommended command-line tool for installing Debian packages on Ubuntu and Debian systems. This command downloads current package metadata; it does not install Java by itself. Wait for it to finish and check for repository errors before proceeding. If the command reports an unreachable repository, an invalid release entry, or a signature problem, fix that repository configuration first. Installing against an old index is a common reason for an apparently missing package.

Choose the right Java package

Java packages differ by purpose. Choosing the smallest package that meets the workload avoids installing a compiler and graphical dependencies on a service that only needs to start an existing application.

Runtime only: JRE

For a VPS that only runs an already-built Java application, install the release-default runtime:

sudo apt install default-jre

A JRE supplies the java launcher and the libraries needed to run Java programs. It does not provide the Java compiler. A versioned alternative follows the pattern:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt install openjdk-<version>-jre

Replace the version with a package that actually exists in the VPS’s repositories. Check availability before putting a versioned name in an automation script.

Development kit: JDK

Install a JDK when the server must compile source code, execute a build, or provide tools such as javac:

sudo apt install default-jdk

The JDK includes the runtime plus development tooling. A version-pinned form is:

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
sudo apt install openjdk-<version>-jdk

For example, Ubuntu’s current developer guidance uses:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt install openjdk-21-jdk

Pinning a major line is useful when an application or build system is certified for that line. APT can then continue to receive the distribution’s updates for that package line.

Headless packages for non-GUI services

A daemon that never creates windows may use the distribution’s headless JRE or JDK variant. Debian defines headless packages as omitting graphical interfaces. This can reduce unnecessary dependencies on a minimal VPS. Before installing, search the repository for the matching headless package and confirm that the application does not require AWT, Swing, JavaFX, or another graphical component:

apt search openjdk

Select the headless variant corresponding to the Java major version and whether you need a JRE or JDK. A GUI-dependent Java application needs the non-headless libraries it uses.

Package decision table

Workload Package pattern Result
Run an existing Java application default-jre or openjdk-<version>-jre Runtime without the compiler
Compile Java or run build tools default-jdk or openjdk-<version>-jdk Runtime, compiler, and development tools
Run a non-GUI service Distribution headless JRE or JDK variant Java without graphical interfaces
Support software locked to a Java major line Versioned openjdk-<version>-jre or -jdk APT-managed updates within that major line

Understand what “default” means

default-jre and default-jdk are release-level package names, not permanent promises about one Java major version. Their dependencies are chosen by the Ubuntu or Debian archive for the release and architecture configured on the VPS. A command copied from a different image can therefore install a different major version even though the command text is identical.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For an interactive installation, this behavior is convenient because the distribution selects the supported default. For repeatable provisioning, inspect the candidate first and record the operating-system release, architecture, and resulting Java version. If the application contract names a major line, use a versioned package rather than relying on the moving default.

apt-cache policy default-jdk
apt-cache depends default-jdk
apt search openjdk

apt-cache policy shows the candidate available from configured repositories, while apt-cache depends exposes the dependency that leads to a particular OpenJDK line. apt search lists package names visible to the current release; it is safer than guessing whether a versioned JRE, JDK, or headless variant exists.

Install Java step by step

Install the default runtime

  1. Refresh metadata: sudo apt update.
  2. Install the runtime: sudo apt install default-jre.
  3. When APT displays the proposed packages and disk-space change, review them and confirm with Y when they match the intended workload.
  4. Continue to the verification commands below.

Install the default development kit

  1. Refresh metadata if the index is not current: sudo apt update.
  2. Install the kit: sudo apt install default-jdk.
  3. Confirm the transaction after reviewing APT’s dependency list.
  4. Verify both java and javac.

Install a specific OpenJDK line

  1. List versions visible to APT with apt search openjdk or inspect the candidate for a generic package with apt-cache policy default-jdk.
  2. Install the required version, for example sudo apt install openjdk-21-jdk.
  3. If the workload only runs programs, choose the corresponding versioned JRE instead of the JDK.
  4. Verify the selected major version after installation.

Ubuntu’s archive provides supported OpenJDK packages for supported LTS releases. Ubuntu 24.04 LTS documentation identifies OpenJDK 17 and 21 as TCK-certified on that release and uses openjdk-21-jdk as its current-LTS example. Certification and package availability still depend on the Ubuntu release and architecture installed on the VPS.

Verify the installation

Check the runtime

Run:

java -version

The output should identify an OpenJDK runtime and its major version. This confirms that the shell can find the java executable through the system alternatives path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Check the compiler when a JDK is installed

javac -version

If java -version succeeds but javac -version returns “command not found,” the VPS has a runtime but not a JDK (or the compiler is not on the active alternatives path). Install the matching JDK package if the server must compile code.

Inspect what APT will install

Before changing an automated image, inspect the candidate package and its dependencies:

apt-cache policy default-jdk
apt-cache depends default-jdk

These commands show the repository candidate and dependency relationships for the release currently configured. They are useful for confirming which Java line a generic package selects instead of assuming that “default” means the same version on every distribution.

Ubuntu and Debian defaults are not identical

Use the distribution’s release data when deciding between a generic package and a versioned one.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Distribution context Documented default or guidance Practical implication
Ubuntu supported LTS releases The Ubuntu Archive provides supported OpenJDK LTS packages. Use default-jre/default-jdk for the release default, or a versioned package when the application requires a specific line.
Ubuntu 24.04 LTS OpenJDK 17 and 21 are TCK-certified; the current-LTS example is openjdk-21-jdk. Confirm the repository candidate on the actual image before pinning 21 in automation.
Debian 12 (Bookworm) OpenJDK 17 is recorded as the default. default-jdk normally follows the Bookworm default, subject to architecture and repository state.
Debian 11 (Bullseye) OpenJDK 11 is recorded as the default. Do not assume a Debian 11 VPS will resolve default-jdk to the same major version as Debian 12 or Ubuntu.

Debian explicitly warns that defaults can differ by architecture. For repeatable provisioning, record the operating-system release, architecture, and package candidate together rather than documenting only the word “Java.”

Make an automated installation repeatable

A provisioning script should discover the image before selecting a package. Capture cat /etc/os-release and dpkg --print-architecture, refresh the index, and then inspect the candidate or search results. This prevents a script written for Debian 12 from silently assuming the same default on Debian 11, Ubuntu, or another architecture.

Choose one policy and document it. A release-default policy uses default-jre or default-jdk and follows the distribution’s selected line. A compatibility policy names a versioned package such as openjdk-21-jdk and fails early if that package is not available. Do not substitute a different major version merely because it happens to be present; verify that the application supports it first.

Keep the package family consistent in the same provisioning step. If the server compiles code, install the JDK rather than installing a JRE first and adding tools later. If it only runs a daemon, use the JRE or headless variant that matches its requirements. After installation, run both version checks that matter to the workload and record their output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Switch between multiple Java installations

Installing a second major version does not necessarily remove the first. Debian manages Java commands through the alternatives system. Do not replace /usr/bin/java by hand; doing so bypasses the package manager and can leave the runtime and compiler pointing at different installations.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

See the available Java environments

sudo update-java-alternatives --list

This lists Java environments known to Debian’s java-common tooling.

Select the active command interactively

To choose the active runtime from the installed alternatives, run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo update-alternatives --config java

Select the path associated with the required installation at the prompt, then confirm it:

java -version

If a build uses the compiler, configure its alternative as well:

sudo update-alternatives --config javac
javac -version

When the runtime and compiler must move together, Debian documents update-java-alternatives as the way to update Java alternatives as a group. This avoids a situation in which java uses one major version while javac uses another.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common APT and Java failures

“Unable to locate package”

The error usually indicates one of four conditions: the local 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.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Run sudo apt update and read the complete output for repository errors.
  2. Check the generic package candidate with apt-cache policy default-jdk.
  3. Search names available to the release with apt search openjdk.
  4. Compare the requested package with cat /etc/os-release and dpkg --print-architecture.
  5. Use the release’s available package name instead of forcing a version that the repository does not provide.

The package installs, but the wrong major version is active

Inspect the installed environments with sudo update-java-alternatives --list, then select the required runtime through sudo update-alternatives --config java. Recheck java -version after the change. If the application invokes the compiler, configure javac separately or switch the complete Java environment with the Debian Java alternatives tooling.

java works but javac is missing

This is the expected symptom when only a JRE was installed. Install the matching default-jdk or versioned openjdk-<version>-jdk package, then run javac -version again.

A graphical application fails on a headless installation

A headless package intentionally omits graphical interfaces. If the program requires GUI libraries, install the corresponding non-headless JRE or JDK package. Keep a headless package for a true server daemon that has no graphical dependency.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

APT repositories and manually extracted Java are mixed

Keep the Java source consistent where possible. Ubuntu and Debian repository packages receive distribution-managed updates and integrate with the alternatives system. Adding a manually extracted Oracle tarball beside APT packages complicates upgrades, path selection, and security maintenance. If a vendor mandates a non-APT distribution, document that exception separately rather than silently mixing it with the repository-managed installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After installation: make the VPS predictable

  • Record the output of java -version, the operating-system release, and dpkg --print-architecture in the deployment notes.
  • Use a versioned OpenJDK package when the application contract names a major Java line; otherwise use the release-default package so normal distribution updates can move it with the operating system.
  • For build servers, verify both java and javac in the same provisioning step.
  • For production daemons, confirm whether the software needs graphical libraries before selecting a headless package.
  • When more than one version is installed, manage it through alternatives commands and never edit the system /usr/bin/java symlink manually.
  • Keep the repository source consistent across the server image so upgrades, alternatives selection, and package ownership remain understandable.

Complete command checklist

The following compact sequence covers the usual JDK installation on an Ubuntu or Debian VPS:

cat /etc/os-release
dpkg --print-architecture
sudo apt update
sudo apt install default-jdk
java -version
javac -version

For a runtime-only server, replace the installation line with sudo apt install default-jre. For a pinned Java 21 development environment where that package is available, use sudo apt install openjdk-21-jdk. If several versions are installed, finish with sudo update-java-alternatives --list and the appropriate alternatives selection command.

Frequently Asked Questions

Should I install a JRE or a JDK on my VPS?

Install default-jre when the VPS only runs an already-built Java application. Install default-jdk when it must compile source code, run a build, or provide javac and other development tools.

What does default-jdk install?

It follows the Java development kit selected by the configured Ubuntu or Debian release and architecture. Check it with apt-cache policy default-jdk and apt-cache depends default-jdk instead of assuming it always means the same major version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I install Java 21 specifically?

First confirm that the VPS repositories provide the package, then run sudo apt install openjdk-21-jdk. Use the corresponding versioned JRE if the server only runs applications, and verify with java -version.

Why does APT say “Unable to locate package”?

Refresh metadata with sudo apt update, inspect repository errors, search with apt search openjdk, and check the release and architecture with cat /etc/os-release and dpkg --print-architecture. The requested package may not exist for that release or architecture.

Why does java work but javac not exist?

A JRE is installed, or the compiler is not selected. Install the matching default or versioned JDK and run javac -version. If several JDKs are installed, configure the compiler with sudo update-alternatives --config javac.

Can I use a headless Java package on a VPS?

Yes, for a non-GUI service that does not require graphical interfaces. Debian’s headless packages omit those interfaces. A program using AWT, Swing, JavaFX, or another GUI dependency needs the corresponding non-headless package.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I change the active Java version?

List environments with sudo update-java-alternatives --list, select the runtime with sudo update-alternatives --config java, and select javac separately when needed. Debian also provides update-java-alternatives to update a Java environment as a group.

Should I mix an Oracle tarball with APT OpenJDK packages?

Avoid mixing sources unless a vendor specifically requires it. Distribution packages receive Ubuntu or Debian managed updates and integrate with alternatives; manually extracted files make upgrades and path selection harder to manage.

The Bottom Line

Identify the VPS release and architecture, run sudo apt update, install the smallest suitable package—default-jre, default-jdk, or an available versioned/headless OpenJDK package—then verify with java -version and, for a JDK, javac -version. Use the alternatives system rather than editing Java symlinks when multiple versions are installed.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.