JDK Download And Installation
To Run Java our own machine JDK needs to get installed on the machine.
To Download:
To download JDK we have to visit official website and select desired version and download it.
Website: https://www.oracle.com/java/technologies/javase-downloads.html
JDK Installation:
On Window:
Method 1: Using the Installer (Recommended)
- Download the
.exeinstaller. - Run the installer and follow the setup wizard.
- Set JAVA_HOME (Environment Variable):
Open System Properties → Advanced → Environment Variables.
Under "System Variables," click New and enter:
Variable Name:JAVA_HOME
Variable Value:C:\Program Files\Java\jdk-XX (Replace XX with the version number - Edit the Path variable and add:
%JAVA_HOME%\bin
5. Verify Installation: Open Command Prompt (cmd) and run:
java -version
javac -version
On MacOS:
Method 1: Using Homebrew (Recommended)
1. Open Terminal and run:
brew install openjdk
2. Add JDK to your environment:
echo 'export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc3. Verify installation:
java -version
Method 2: Manual Installation
- Download the
.dmgfile from the Oracle website. - Open the installer and follow the instructions.
- Verify with:
java -version
Linux Installation (Ubuntu/Debian)
Method 1: Install OpenJDK (Recommended)
1. Update package index
sudo apt update
2. Install JDK (e.g., JDK 17)
sudo apt install openjdk-17-jdk -y
3. Verify Installation
java -version
javac -versionMethod 2: Install Oracle JDK
- Download the
.tar.gzfile from Oracle. - Extract and move it to
/usr/lib/jvm
sudo mkdir -p /usr/lib/jvm
sudo tar -xvzf jdk-XX.tar.gz -C /usr/lib/jvm
3. Set Java alternatives:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-XX/bin/java 1
sudo update-alternatives --config java4. Verify installation:
java -version
Set Up JAVA_HOME
For Window JAVA_HOME set up is already mentioned above.
For MacOs/Linux follow below steps:
Add below command in ~/.bashrc or ~/.zshrc:
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$JAVA_HOME/bin:$PATHThen, reload:
source ~/.zshrc # or source ~/.bashrc
Verify the Installation
java -version
javac -version
echo $JAVA_HOME
