Linux command
update-java-alternatives 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
List all installed Java versions
update-java-alternatives --list
Switch to a specific Java version
sudo update-java-alternatives --set [java-17-openjdk-amd64]
Set all Java alternatives to automatic mode
sudo update-java-alternatives --auto
Only switch JRE
sudo update-java-alternatives --jre --set [java-17-openjdk-amd64]
Test what would be done
update-java-alternatives --test --set [java-17-openjdk-amd64]
说明
update-java-alternatives manages multiple Java installations on Debian and Ubuntu systems. It is a wrapper around the update-alternatives system specifically designed for Java, updating all Java-related binaries (java, javac, jar, javadoc, etc.) simultaneously. When switching Java versions, this tool ensures all associated commands point to the same installation, preventing version mismatches between the JRE and JDK tools. This is essential for development environments that require specific Java versions. The jname parameter corresponds to the directory name under /usr/lib/jvm/ for the Java installation. Use --list to see available installations and their names. The tool is part of the java-common package on Debian-based systems.
参数
- -l, --list _jname_
- List all installed Java packages, or details about a specific installation.
- -s, --set _jname_
- Set all alternatives to the specified Java installation.
- -a, --auto
- Switch all alternatives to automatic mode, letting the system choose the highest priority version.
- --jre
- Limit actions to runtime environment alternatives only, not development kit tools.
- --jre-headless
- Limit actions to headless runtime alternatives (no GUI support).
- --plugin
- Limit actions to browser plugin alternatives.
- -t, --test
- Dry run mode. Show what would be done without making changes.
- -h, --help
- Display help message.
FAQ
What is the update-java-alternatives command used for?
update-java-alternatives manages multiple Java installations on Debian and Ubuntu systems. It is a wrapper around the update-alternatives system specifically designed for Java, updating all Java-related binaries (java, javac, jar, javadoc, etc.) simultaneously. When switching Java versions, this tool ensures all associated commands point to the same installation, preventing version mismatches between the JRE and JDK tools. This is essential for development environments that require specific Java versions. The jname parameter corresponds to the directory name under /usr/lib/jvm/ for the Java installation. Use --list to see available installations and their names. The tool is part of the java-common package on Debian-based systems.
How do I run a basic update-java-alternatives example?
Run `update-java-alternatives --list` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -l, --list _jname_ do in update-java-alternatives?
List all installed Java packages, or details about a specific installation.