It would be a safer/more cautious approach not to change the default Java environment system-wide just to run different versions of a single program.
You can, instead, start a program with a modified PATH
to make it use a specific Java version (as suggested in the Arch Linux Wiki, where archlinux-java
is documented):
$ PATH="/usr/lib/jvm/java-<version>-openjdk/bin${PATH:+:$PATH}" your_program
If you use a .desktop
file to launch your program, edit its Exec
key:
Exec=env PATH="/usr/lib/jvm/java-<version>-openjdk/bin${PATH:+:$PATH}" your_program
Or, alternatively, using the GUI, adjust its "Properties" → "Application": "Command" field.
If you really want to allow a user to run sudo archlinux-java
without being prompted for a password, you can add
your_user ALL=(root) NOPASSWD: /usr/bin/archlinux-java
to your /etc/sudoers
, after any already present your_user
lines. Remember to use visudo
to do that: it checks the sudoers
file for errors before saving it, reducing the risk of making sudo
unusable.
Further reading: