Learn how to install Java on Windows, macOS, and Linux, configure environment variables, and set up your system for Java development. This guide ensures you are ready to create powerful Java applications effortlessly.
How to Set Up Java on Your System.
A Comprehensive Step-by-Step Guide :
Description:
Learn how to install Java on Windows, macOS, and Linux, configure environment variables, and set up your system for Java development. This guide ensures you are ready to create powerful Java applications effortlessly.
Step 1: Download the Java Development Kit (JDK)
What is JDK?
The Java Development Kit (JDK) is essential for building Java applications. It includes the Java Runtime Environment (JRE), libraries, and development tools.
Installation Instructions:
For Windows:
- Visit the Oracle JDK Download Page
- Go to the official Oracle JDK page and select the latest version.
- Choose the Windows Version
- Download the JDK matching your system architecture (32-bit or 64-bit).
- Accept the License Agreement
- Check the box to agree to the license terms.
- Download and Run the Installer
- Double-click the .exe file and follow the on-screen instructions, opting for default settings unless specific customizations are required.
For macOS:
- Visit the Oracle JDK Download Page
- Navigate to the Oracle JDK page and choose the macOS version.
- Download the .dmg File
- Click the download link for the .dmg installer.
- Install the JDK
- Double-click the .dmg file, mount the installer, and follow the prompts.
For Linux:
- Visit the Oracle JDK Download Page
- Select the appropriate .tar.gz file for your distribution.
- Install OpenJDK via Package Manager (Optional)
- For many Linux distributions, use OpenJDK:
- On Ubuntu/Debian: sudo apt update && sudo apt install openjdk-17-jdk
- On Fedora: sudo dnf install java-17-openjdk-devel
- On CentOS/RHEL: sudo yum install java-17-openjdk-devel
Step 2: Set Up Environment Variables
Setting environment variables ensures Java can be accessed from the command line.
For Windows:
- Open System Properties
- Right-click This PC > Properties > Advanced system settings.
- Add JAVA_HOME
- Under System Variables, click New and set:
- Variable Name: JAVA_HOME
- Variable Value: Path to your Java installation (e.g., C:\Program Files\Java\jdk-17).
- Update Path Variable
- Edit the Path variable and add: C:\Program Files\Java\jdk-17\bin.
- Apply Changes
- Click OK to save and close.
For macOS:
- Edit Shell Configuration File
- For Zsh: nano ~/.zshrc
- For Bash: nano ~/.bash_profile
- Set JAVA_HOME and Update PATH
Add the following:
- export JAVA_HOME=$(/usr/libexec/java_home)
- export PATH=$JAVA_HOME/bin:$PATH
- Apply Changes
- Save the file and run: source ~/.zshrc (or source ~/.bash_profile).
For Linux:
- Edit Shell Configuration File
- For Bash: nano ~/.bashrc
- For Zsh: nano ~/.zshrc
- Set JAVA_HOME and Update PATH
Add the following:
- export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
- export PATH=$JAVA_HOME/bin:$PATH
Apply Changes
Save the file and run: source ~/.bashrc (or source ~/.zshrc).
Step 3: Verify the Java Installation
Open Command Line/Terminal
Windows: Open Command Prompt.
macOS/Linux: Open Terminal.
Check Java Version
Run: java -version
Expected output:
java version "17.0.x" 2024-xx-xx LTS
Java(TM) SE Runtime Environment (build 17.0.x+xx)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.x+xx, mixed mode)
Step 4: Install an Integrated Development Environment (IDE)
- Using an IDE simplifies Java development. Popular options include:
- IntelliJ IDEA: User-friendly and feature-rich.
- Eclipse: Open-source with extensive plugin support.
- NetBeans: Great for JavaFX and enterprise development.
Visit their websites to download and install the IDE of your choice.
YouTube link
Core Java Tutorial 01 : Understanding Java, Setup & Real-World Applica...