Installing Java on macOS
To install Java on macOS, follow these steps:
Step 1: Download the JDK
Go to the Oracle JDK download page, choose the latest JDK version, and download the appropriate .dmg
installer.
Step 2: Install the JDK
Open the .dmg
file you downloaded and follow the prompts to install the JDK. You may need to enter your administrator password during the installation process.
Step 3: Set Environment Variables
Once the installation is complete, you need to configure environment variables so your system knows where Java is installed. Open the Terminal and type:
nano ~/.bash_profile
This command opens the .bash_profile
in a text editor. Add the following lines to set the JAVA_HOME
variable:
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
Press Ctrl + X
to exit, Y
to save the changes, and Enter
to confirm. Close and reopen the Terminal to apply the new settings.
Step 4: Verify the Installation
To confirm Java is installed correctly, check its version with the following command:
java -version
If you encounter an error, it indicates the installation wasn’t successful.