install-jdk
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
-
ModuleNotFoundError: No module named 'jdk'
cause The `install-jdk` package was not installed or is not accessible in the current Python environment.fixRun `pip install install-jdk` in your active virtual environment or global Python installation. -
ValueError: Could not find a suitable JDK version for '1.8' (or similar for other versions/impls)
cause The specified JDK version, JVM implementation, or variant combination could not be found or is not supported by the available providers. This can happen with very old, pre-release, or incorrect version strings.fixDouble-check the exact version string (e.g., use '8' instead of '1.8' for Java 8, or '17' for Java 17). Verify the `jvm_impl` (e.g., 'adoptium', 'corretto', 'zulu') and `jvm_variant` (e.g., 'hotspot', 'openjdk') are correct and supported. -
PermissionError: [Errno 13] Permission denied: '/path/to/.jdk'
cause The user running `install-jdk` does not have write permissions to the default installation directory (usually `~/.jdk`) or a custom `install_dir` provided.fixRun the script with appropriate user permissions, or specify an `install_dir` where the user has write access, e.g., `jdk.install('17', install_impl='adoptium', install_dir='/tmp/my_jdks')`.
Warnings
- gotcha install-jdk installs JDKs to a local cache directory (e.g., `~/.jdk` or a custom `install_dir`), but it does not automatically modify system-wide PATH or set `JAVA_HOME` for your operating system. You must manually configure these environment variables for applications to find the installed JDK.
- gotcha The library explicitly requires Python versions `>=3.6,<4.0`. Using Python 3.10 or newer will result in installation errors or unexpected runtime behavior.
- gotcha JDK installation requires active internet access to download binaries from remote servers. Network issues, firewalls, or proxy configurations can cause installation failures.
- gotcha When calling `jdk.install()`, if you omit `jvm_impl`, it defaults to 'adoptium'. If you expect a different vendor (e.g., Corretto or Zulu), you must explicitly specify it.
Install
-
pip install install-jdk
Imports
- jdk
import jdk
Quickstart
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}")