0

I have to bounce between Java 8 and Java 13 for different Minecraft versions to work properly, and doing that requires me to type sudo archlinux-java set java-8-openjdk or sudo archlinux-java set java-13-openjdk - the problem is I want to turn this into a simple double-clickable script I can put on my desktop, and not have it prompt me for the password.

Is there anything I can chmod or something that makes it such that this command doesn't require sudo?

Dr-Bracket
  • 377
  • 1
  • 5
  • 21

1 Answers1

0

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:

fra-san
  • 10,205
  • 2
  • 22
  • 43