⏱️ 6 min read • Beginner Level • Lesson 5
Completed on . You can revise this lesson or continue to the next topic.
Before you start writing Java programs, you need to set up the Java environment. This means installing the Java Development Kit (JDK), configuring the PATH variable, and verifying that Java commands work correctly from the terminal or command prompt.
If you are new to Java, you may first read the Java introduction lesson and then continue with this setup guide.
To compile and run Java programs, you need the Java Development Kit (JDK).
The JDK includes important tools like javac for compiling
Java source code and java for running Java programs.
After installation, the PATH environment variable helps your system locate Java commands from any folder.
The setup process differs slightly for Windows, Linux, and macOS.
You can install JDK from Oracle JDK or an OpenJDK distribution. Choose the installer according to your operating system and system architecture.
bin path while setting environment variables.
\bin path.
C:\Program Files\jdk-21\bin
sysdm.cpl, and press Enter.
bin path.
javac -version
To check if Java is installed, run:
java -version
If it shows command not found or an older version, you need to install Java or update the PATH.
C shell (csh):
set path=(/usr/local/jdk/bin $path)
Bash shell:
PATH=/usr/local/jdk/bin:$PATH
export PATH
sh shell:
PATH=/usr/local/jdk/bin:$PATH
export PATH
After updating PATH, reload your shell configuration file and verify with:
java -version
On macOS, you can use the java_home tool to detect installed Java versions.
/usr/libexec/java_home -V
To check the Java compiler version, run:
javac -version
java -version and javac -version to verify your setup.Next step: Learn the Java Program Structure.
🧠 Test your understanding with a quick quiz
Topic: Java_environment_setup | Language: Java
🎉 Great job! Continue learning Java step by step.
Mark this lesson as completed to track your learning progress. To keep track across devices, please login and save your learning progress.
Discussion
Ask questions, share suggestions, or discuss this lesson.