Here is an idea to do “javaenv” with Fish’s universal variable and usr/libexec/java_home
.
This isn’t looking so much useful, but works enough. You can put this script in ~/.config/fish/functions
to use.
You can see the list of installed Java on your machine with the following command:
🍣 javaenv
On my machine there’s Java 11 and Java 8 installed. So the result will be the following:
Matching Java Virtual Machines (2):
11.0.1, x86_64: "OpenJDK 11.0.1" /Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home
1.8.0_192, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home
You can set the Java version to use with the following command:
🍣 javaenv set 1.8
This command will set JAVA_HOME
into the home directory of Java 8. Fish’s universal variable will be kept like as an environment variable unless you delete it explicitly. So the Java version you’ve set will be kept even if you logged out and logged on again.
By the way, usr/libexec/java_home
is preinstalled on macOS. This command recognize the version you give as forward match. That’s why if there’s Java 11 was installed on your machine and you inputted javaenv set 1
, the current Java version would be Java 11.