Programming With Java
This guide provides step-by-step instructions to install Java on Windows, Linux, and macOS.
Windows Installation
1. Download Java
- Visit the official Java download page.
- Under Java SE (Standard Edition), select the latest JDK version (e.g., JDK 20).
- Click on the Windows installer link (
.exe).
2. Run the Installer
- Double-click the
.exefile to start the installation. - Follow the prompts, leaving the default settings as they are. Click Next until the installation begins.
3. Set Up Environment Variables
- Right-click on
This PCorComputerand select Properties. - Click on Advanced system settings > Environment Variables.
- Under System variables, click New and set
JAVA_HOMEto the path of the Java installation directory (e.g.,C:\Program Files\Java\jdk-20). - Edit the
Pathvariable and add%JAVA_HOME%\bin.
4. Verify Installation
- Open the Command Prompt.
- Type
java -versionand press Enter. The Java version should be displayed.
Linux Installation
1. Download Java
- Go to the official Java download page.
- Select the latest JDK version (e.g., JDK 20) and download the
.tar.gzfile.
2. Install Java
- Open the Terminal and navigate to the downloaded file's directory.
- Extract the file with:
tar -xvzf jdk-20_linux-x64_bin.tar.gz - Move the extracted folder to
/opt:sudo mv jdk-20 /opt/ - Set up JAVA_HOME by adding the following to
.bashrcor.bash_profile:export JAVA_HOME=/opt/jdk-20
export PATH=$JAVA_HOME/bin:$PATH - Apply the changes with:
source ~/.bashrc
3. Verify Installation
- Open a new Terminal window.
- Type
java -versionand press Enter. The Java version should be displayed.
macOS Installation
1. Download Java
- Go to the official Java download page.
- Download the latest JDK
.dmgfile for macOS.
2. Install Java
- Double-click the
.dmgfile and follow the installation prompts. - Set up JAVA_HOME:
- Open Terminal and run:
/usr/libexec/java_home -V - Copy the JDK path and add the following to
.zshrc,.bash_profile, or.zprofile:export JAVA_HOME=$(/usr/libexec/java_home -v <jdk_version>)
export PATH=$JAVA_HOME/bin:$PATH - Replace
<jdk_version>with the version number you installed. - Apply the changes with:
source ~/.zshrc # or source ~/.bash_profile
- Open Terminal and run:
3. Verify Installation
- Open Terminal.
- Type
java -versionand press Enter. The Java version should be displayed.
Note: These steps should ensure Java is installed and ready to use on your system.