![Setting JAVA_HOME on macOS Setting JAVA_HOME on macOS](https://code2care.org/java/setting-java_home-environment-variable-in-macos-mac-os-x/images/Setting JAVA_HOME on macOS.png)
In this article, we will take a look at how to set the $JAVA_HOME environment variable on the Mac running macOS (or Mac OS X for older versions),
What is $JAVA_HOME?
JAVA_HOME is an Environment Variable that is set on the Operating System (be it Linux, Ubuntu, macOS, or Microsoft Windows) to set the Java JDK (Java Development Environment) or JRE (Java Runtime Environment) and provide the location where the JDK/JRE is installed.
What is the use of JAVA_HOME?
JAVA_HOME is used by the programs that make use of Java or require Java runtime in order to run. Such programs example Eclipse, Tomcat, GlassFish, Oracle SQL Client, Gradle, Maven, Jenkins, Android Studio, etc.
Also if you want to run Java from the command line using the javac and java commands, you would need to set the Java home path in your environment variable.
What is set $JAVA_HOME on macOS (earlier known as Mac OS X)?
If you are using Zsh shell:
- Open Terminal App,
- Find out where Java is installed on your Mac device:
/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
- Now open .zshrc profile file from home directory,
nano ~/.zshrc
Add the below line in the file (note you Java installation might be different,
export JAVA_HOME="/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home"
Save file file by pressing Control + X and typing Y to save.
- Apply the changes by excuting the command: source ~/.zshrc
To validate if JAVA_HOME is set or not, type command,
% echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
%
If you are using Bash shell:
If you are using the Bash terminal then the above steps remain the same, just instead of .zshrc file you will use .bashrc file.
How to find macOS version?
To find your macOS (or Mac OS X) version you can make use of the command sw_vers, you will have one of these,
macOS Monterey (Latest): 12.2.1
macOS Big Sur: 11.6.4
macOS Catalina: 10.15.7
macOS Mojave: 10.14.6
macOS High Sierra: 10.13.6
macOS Sierra: 10.12.6
OS X El Capitan: 10.11.6
OS X Yosemite: 10.10.5
OS X Mavericks: 10.9.5
OS X Mountain Lion: 10.8.5
OS X Lion: 10.7.5
Mac OS X Snow Leopard: 10.6.8
Mac OS X Leopard: 10.5.8
Mac OS X Tiger: 10.4.11
Mac OS X Panther: 10.3.9
Mac OS X Jaguar: 10.2.8
Mac OS X Puma: 10.1.5
Mac OS X Cheetah: 10.0.4
- Fix: grunt: command not found (Mac/Windows)
- AppleScript Example with TextEdit
- How to copy Password of Wifi on your Mac
- Install OpenJDK Java (8/11/17) versions using brew on Mac (Intel/M1/M2)
- How to check if a port is in use using terminal [Linux or macOS]
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to Remove Widgets from macOS Sonoma 14 Desktop
- Turn off Auto-Capitalization on macOS Ventura 13
- How to Go To /usr/local/bin on Mac Terminal?
- How to Open TextEdit on Mac
- Mac: How to Open Android Studio from Terminal
- How to change the default location of Mac Screenshot
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- How to install homebrew (brew) on M1 Mac
- Must Know Homebrew Commands for Mac/Linux Users
- Steps to Uninstall Roblox on Mac (macOS)
- How to change the System Settings Sidebar icon size Mac Ventura 13
- How to set Out Of Office (OOO) on Outlook for Mac [Updated 2023]
- Trigger Notification Center Message using Mac Terminal Command
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools
- How to Install Rust Language on Mac (macOS)
- How to minimize all Windows in Mac
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to make TextEdit the default text Editor on Mac
- Create S3 bucket and upload files using AWS Toolkit for Visual Studio Code - AWS
- How to get UTC (GMT) time using JavaScript - JavaScript
- How to take user input from the console in a Python program - Python
- [fix] URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs) IntelliJ - Java
- Android Error Unexpected cast to Button: layout tag was FrameLayout - Android
- Android M cannot run app using play button : Android Studio - Android
- [fix] iCloud - Verification Failed: An unknown error occurred Apple ID - iOS
- Steps to Install Jenkins on M1/M2 Mac - MacOS