Skip to content

Instantly share code, notes, and snippets.

@alonsoir
Forked from tobias/setjdk.fish
Last active September 2, 2019 11:05
Show Gist options
  • Save alonsoir/fb0e6e012a33a802a91801ccd68b30f3 to your computer and use it in GitHub Desktop.
Save alonsoir/fb0e6e012a33a802a91801ccd68b30f3 to your computer and use it in GitHub Desktop.
Manage multiple java versions on the mac from the fish shell
# quick way to change previous JAVA_HOME to jdk 8 version.
set -x JAVA_HOME (/usr/libexec/java_home -v 1.8)
function setjdk
if test -n "$JAVA_HOME"
removeFromPath "$JAVA_HOME/bin"
end
set -gx JAVA_HOME (/usr/libexec/java_home -v $argv[1])
set -gx PATH $JAVA_HOME/bin $PATH
end
function removeFromPath
set -l idx 0
for x in (seq (count $PATH))
if test "$argv[1]" = "$PATH[$x]"
set idx $x
end
end
if test $idx -gt 0
set -e PATH[$idx]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment