Skip to content

Instantly share code, notes, and snippets.

@melsoriano
Last active January 16, 2020 00:51
Show Gist options
  • Save melsoriano/26920869f65af51447f217b282f2e5fd to your computer and use it in GitHub Desktop.
Save melsoriano/26920869f65af51447f217b282f2e5fd to your computer and use it in GitHub Desktop.
Changing default Java version on Mac OS
  1. Verify the default Java version in terminal by running the command: java -version

  2. Download the appropriate JDK from Oracle website for Mac OS

  3. After installation completes, cd into /usr/libexec from a terminal window

  4. From the libexec directory, verify all installed Java versions by running the command: ./java_home -V

  5. Open your shell config file

    • zsh & vscode users, run: code ~/.zshrc
    • bash & vscode users, run: code ~/.bash_profile
  6. Paste the following in the file: export JAVA_HOME=$(/usr/libexec/java_home -v version_of_your_java)

    • Replace the version_of_your_java with the JDK version you want to set. For example, java version "1.8.0_171" will be 1.8.0_171
  7. Save the file

    • If you are using zsh run the command source ~/.zshrc to save changes made to the file
  8. Verify the changes by running the command: java -version this should be 1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment