Java Installation on Different Operating Systems
To run and compile Java programs, we must first install the JDK (Java Development Kit). It contains:
- Java Compiler (
javac
) - Java Runtime Environment (JRE)
- Java Virtual Machine (JVM)
Let's see how to install Java on different operating systems.
1. Installing Java on Windows
- Go to the official Oracle JDK download page: Oracle Downloads
- Choose the correct version for Windows and download the .exe installer.
- Double-click the downloaded file and follow the installation steps.
- After installation, set the Environment Variable:
- Search “Environment Variables” in Windows search.
- Edit the
Path
variable under System Variables. - Add the path where Java is installed, example:
Default Path (if installed normally):
C:\Program Files\Java\jdk-version\bin
Custom Path (if installed by user):
C:\Users\ShikshaSanchar\Java\jdk-17.0.2\bin
- To confirm, open Command Prompt and type:
java -version javac -version
- If versions appear, Java is successfully installed.
2. Installing Java on macOS
- Visit: Oracle Downloads
- Download the macOS .dmg installer.
- Open the .dmg file and follow the install wizard.
- After install, open Terminal and run:
java -version javac -version
- If you see the installed versions, you're ready to run Java.
3. Installing Java on Linux (Ubuntu/Debian)
- Open Terminal.
- Run the following commands one by one:
sudo apt update sudo apt install default-jdk
- To check installation:
java -version javac -version
- Java should now be installed and ready to use.
4. Online Java Compilers (No Installation Needed)
If you don’t want to install anything, you can also run Java code directly in your browser using these online compilers:
These tools are useful for quickly testing Java code or learning without installation.
5. Verifying Java Installation
After installing Java, you can check the version by typing the following commands in your Command Prompt or Terminal:
C:\Users\ShikshaSanchar> java -version
java version "17.0.2"
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode)
C:\Users\ShikshaSanchar> javac -version
javac 17.0.2
If these commands show version numbers, Java is installed successfully. If not, recheck environment variable setup.
Note:
- JDK version can vary — use the latest stable version (like JDK 17 or JDK 21).
- You must install JDK (not just JRE) to compile Java code.
Summary:
- Windows: Download and install .exe, set environment variables.
- macOS: Install from .dmg file and verify in terminal.
- Linux: Use
apt install default-jdk
. - Check installation:
java -version
andjavac -version