install-jdk

1.1.0 · active · verified Thu Apr 16

install-jdk is a Python library that simplifies the process of installing OpenJDK distributions. It supports popular OpenJDK builds from Adoptium (formerly AdoptOpenJDK), Amazon Corretto, and Zulu, allowing developers to easily manage Java environments. The current version is 1.1.0, and it maintains a moderate release cadence with updates for dependencies and minor features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart installs the latest OpenJDK 17 from Adoptium to a specified directory (defaulting to a temporary path to avoid permissions issues). It demonstrates the core `jdk.install()` function and prints the installation path. Users would typically use this `install_path` to configure their `JAVA_HOME` environment variable or invoke the Java executable directly.

import jdk
import os

# Install the latest OpenJDK 17 from Adoptium to a temporary directory
# This makes it runnable without affecting user's home directory
install_path = jdk.install(
    '17',
    jvm_impl='adoptium',
    install_dir=os.environ.get('JDK_INSTALL_DIR', '/tmp/jdk_install_cache')
)

print(f"OpenJDK 17 installed at: {install_path}")

# You can then use this path to set JAVA_HOME or run Java commands
# For example, to print the Java version:
# import subprocess
# java_bin = os.path.join(install_path, 'bin', 'java')
# if os.path.exists(java_bin):
#     try:
#         result = subprocess.run([java_bin, '-version'], capture_output=True, text=True, check=True)
#         print(result.stderr) # Java version typically prints to stderr
#     except subprocess.CalledProcessError as e:
#         print(f"Error running Java: {e.stderr}")

view raw JSON →