Skip to content

Instantly share code, notes, and snippets.

@MinhOmega
Last active September 7, 2024 07:27
Show Gist options
  • Select an option

  • Save MinhOmega/b2ad13638ef2ea7b836de12d58be95e5 to your computer and use it in GitHub Desktop.

Select an option

Save MinhOmega/b2ad13638ef2ea7b836de12d58be95e5 to your computer and use it in GitHub Desktop.
Update JAVA Path with command line

To switch to Java 11 using the specified JDK path, you can follow these steps:

  1. First, set the JAVA_HOME environment variable to point to the Java 11 installation:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
  1. Then, update your PATH to use the new Java version:
export PATH=$JAVA_HOME/bin:$PATH
  1. To make these changes permanent, add these lines to your shell configuration file (e.g., ~/.zshrc or ~/.bash_profile):
echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home' >> ~/.zshrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.zshrc
  1. Reload your shell configuration:
source ~/.zshrc
  1. Verify that Java 11 is now being used:
java -version

This should now show Java 11 as the current version.

If you're using a version manager like jenv, you can add this Java version and set it as the global version:

jenv add /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
jenv global 11

Remember that after changing your Java version, you might need to clean and rebuild your React Native project:

cd android
./gradlew clean
cd ..
npx react-native run-android

This should ensure that your project is using Java 11 for the build process.

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