Java Get Started: Install the JDK and Set Up Your Editor
Get one Java toolchain working end to end: install a JDK, prove that your terminal can find it, and make your editor run the same saved file. A short repeatable check is more useful than an installer success screen.
Prerequisite: Java Introduction. You will need an internet connection, permission to install development tools, and a folder where you can save files. The on-page runner lets you try the Java examples without installing tools, but cannot verify your computer's setup.
What you will be able to do
- Choose the right JDK package for your operating system and processor.
- Verify the compiler and runtime in a fresh terminal.
- Explain PATH and JAVA_HOME without confusing their roles.
- Compile, run, edit, and recompile Main.java from a practice folder.
- Make your editor and terminal use the intended project JDK.
- Diagnose a setup failure from evidence instead of repeatedly reinstalling Java.
The short answer: what should you install?
For this course, install a Java 21 JDK and use a text editor with Java support. Eclipse Temurin is one OpenJDK distribution you can use. Select JDK rather than JRE: you need the compiler as well as the runtime. Java 21 is our teaching baseline, not a claim that it is the newest Java release.
A successful setup is not just an installer finishing. You should be able to open a fresh terminal, ask both java and javac for their versions, compile Main.java, and run Main. Only then add the editor's Run button to the workflow. This separates a toolchain problem from an editor configuration problem.
Follow the instructions for your operating system only. If you already have a working Java 21 JDK, verify it instead of installing another copy. On a managed school or work computer, use the approved installation process; do not bypass administrative controls.
Before downloading: check these three things
First, identify your operating system. Windows, macOS, and Linux need different packages. Next, check the processor architecture. Apple Silicon Macs use ARM64/aarch64; Intel Macs use x64. On Windows, look under Settings → System → About for the system type. On Linux, uname -m commonly reports x86_64 for x64 or aarch64 for ARM64.
Finally, create a java-practice folder under your personal documents using your file manager. Open that folder in the editor later. Keep the first example out of system directories and out of an existing application's source tree. You need permission to install the JDK, enough free disk space, and permission to create and save files in your practice folder. If the vendor does not offer a package for your architecture, consult its supported-platform instructions rather than choosing an incompatible installer.
The previous Introduction lesson explains the JDK and JVM. Here we will keep main's structure intact and focus on the tools. You do not need Maven, Gradle, Spring, a database, or a JavaScript runtime for this lesson.
uname -mUse this to help choose the download architecture; macOS About This Mac also identifies an Apple chip or Intel processor.
Windows: install a Java 21 JDK
Use the official Temurin release page. Select Windows, Java 21, JDK, and your processor architecture, then download the matching MSI installer. Avoid choosing a JRE package or copying an installer link from an unrelated download site.
In the installer, review the installation location and features. Enable the PATH feature and, if offered, the JAVA_HOME feature. Keep existing environment-variable entries rather than replacing the whole PATH. Finish, close old terminal windows, and open a new PowerShell window.
If you already use WinGet, the command below is an alternative to the MSI download, not an additional required installation. Review the package and prompts before accepting. After either method, continue to the common verification section.
If you need to configure the user environment manually, search Windows for Edit environment variables for your account. Set JAVA_HOME to the actual installed JDK folder, then add its bin folder as an entry in the user Path list. Do not replace the entire list. Confirm the folder in File Explorer instead of guessing a versioned directory name, and open a fresh terminal to test.
- Choose a matching Windows JDK installer from the official release page.
- Install it with the PATH feature enabled; note its installation directory.
- Open a new PowerShell window and verify both tools.
winget install --id EclipseAdoptium.Temurin.21.JDK --exactChoose this method or the MSI installer. Do not install a second copy just because two methods are shown.
java -version
javac -version
Get-Command java, javac | Select-Object Name, Source
$env:JAVA_HOMEBoth version commands should identify Java 21 for this course. Source shows which executable PowerShell resolves. A blank JAVA_HOME is different from a missing executable.
macOS: choose Apple Silicon or Intel
Download the Java 21 JDK PKG for macOS from Temurin, choosing aarch64 for Apple Silicon or x64 for Intel. Follow the package installer. Then open a new Terminal window so it can discover the installation.
macOS can have several JDKs installed. The java_home helper lists registered JDKs and can select version 21. Use the commands below to select it for the current terminal session, then verify both tools. A session-only change is useful when checking a configuration because it does not rewrite your shell startup files.
If you want this selection in future shells, add the two export lines once to the startup file appropriate for your shell; for the usual interactive zsh terminal that is ~/.zshrc. Review existing Java settings first. Do not paste duplicate exports repeatedly or remove other tools from PATH.
/usr/libexec/java_home -VConfirm a Java 21 installation is listed. If it is not, recheck the installed package and architecture before editing shell settings.
export JAVA_HOME="$(/usr/libexec/java_home -v 21)"
export PATH="$JAVA_HOME/bin:$PATH"
java -version
javac -versionRun this only after the helper lists version 21. The original PATH is retained after the selected JDK's bin directory.
Linux: use instructions for your distribution
On Ubuntu 24.04 LTS, the repository package below installs the OpenJDK 21 development kit. The administrator password prompt belongs to your computer; nothing you type there is Java source. Read package-manager output before confirming changes.
These apt commands are not universal Linux commands. For Fedora, Debian releases with different repositories, or another distribution, use its supported Java packages or follow Temurin's official distribution-specific installation guide. If the package cannot be found, check the supported repositories and release rather than downloading a random script to run as root.
Multiple JDKs may coexist on Linux. If java and javac resolve to different versions, inspect their executable paths. On Ubuntu, update-alternatives can select each command; check both rather than assuming switching java also switched javac.
sudo apt update
sudo apt install openjdk-21-jdkThis is an operating-system installation, not a command to run in the lesson's Java editor.
java -version
javac -version
command -v java
command -v javac
readlink -f "$(command -v java)"
readlink -f "$(command -v javac)"Run the readlink checks after both commands are found. They help distinguish a selection link from the JDK executable it targets.
sudo update-alternatives --config java
sudo update-alternatives --config javacReview the listed choices and select the intended version for each. Skip this if the tools already match; it changes the selected system alternatives.
Verify the tools before configuring the editor
Open a fresh terminal after installation and run java -version and javac -version. For this course, both should report major version 21. Vendors and patch numbers may differ; you do not need to reproduce one screenshot character for character. Neither command should be missing.
PATH is the list of directories your shell searches for a command. If an older Java installation appears earlier, java may select it even though a new JDK is installed. JAVA_HOME is a separate variable some tools use to locate a JDK. Setting it alone does not necessarily change which java command your shell finds.
JAVA_HOME should identify the JDK's root directory, not its bin directory or the java executable. A minimal command-line program can work without this variable when PATH is correct. Set it when your chosen tools need it or when deliberately selecting among installations. Confirm paths and versions rather than assuming a variable's existence proves the setup is right.
java -version
javac -versionTypical output includes a runtime version beginning with 21 and javac 21 followed by a vendor-specific patch version. Version output may be written to the terminal's error stream; that alone is not a failure.
Set up one editor, not a stack of tools
VS Code is one option used in this walkthrough. Install it from the official site, then add Microsoft's Extension Pack for Java from the Extensions view. Use the extension's documented runtime requirements if it requests an additional tooling JDK: the JDK running a language server can differ from the Java 21 JDK selected for your project.
Open your java-practice folder with File → Open Folder instead of opening a detached file in an unrelated workspace. Review any workspace-trust prompt and trust only a folder whose contents you know. Create Main.java there. Wait for Java language support to initialize before expecting Run or Debug actions.
Open the Command Palette and use Java: Configure Java Runtime to inspect the project runtime. Point the project at your intended JDK. Then open the editor's integrated terminal and repeat the version checks. That terminal can inherit an older environment if the editor was already open during installation; restarting the editor may be necessary.
An IDE such as IntelliJ IDEA is also a valid choice. You do not need to install both. Whatever editor you choose, retain the terminal workflow below as an independent check. Completion suggestions and a green Run button are helpful tools, not substitutes for knowing which source file and JDK are being used.
Compile and run a file you can locate
Create Main.java in your practice folder and copy the verification program below. Save it as plain text with the exact filename, not Main.java.txt. The public class is named Main, so capitalization matters. Keep this first file outside a package so there is no extra directory or classpath setup to learn yet.
Open a terminal in that folder. In VS Code, opening Terminal → New Terminal from the opened practice folder is a convenient starting point. Use cd followed by your folder's actual path in quotes if necessary. On Windows, Get-Location and Get-ChildItem show your location and files; on macOS or Linux, use pwd and ls. Confirm Main.java is actually listed before compiling. Being in the wrong folder is a common cause of file-not-found errors.
Compile with javac Main.java. Successful compilation is commonly quiet and should create Main.class. Run with java Main: this command names the class, not the filename Main.class. The program should print the two lines shown below. The next lesson will examine the syntax in more detail.
Now change the second message, save the source, compile again, and launch again. The new message should appear. If it does not, you might be running an older class file or editing another Main.java. Check the folder and timestamp before changing configuration at random.
javac Main.java
java MainThese are two separate commands. Continue to the launch step only after the compile step succeeds. Do not type them into the Java source editor.
Main.java · Verify the Java workflow
Predict the result, edit Main.java, then run your program.
Standard input · optional
Select Run code to compile and execute this program.
Java setup ready
Next step: learn Java syntaxCopy this source to your own Main.java and repeat the terminal commands above. The on-page result and your local result should contain the same messages. That comparison checks the behavior; your local version and path checks establish which tools produced it.
Check that the editor and terminal agree
Run the saved file through your editor and compare its two messages with your terminal run. If they differ, investigate the source path, the active project, unsaved changes, and the selected JDK. An editor can compile a different workspace or use a different runtime from the one found by your shell.
The optional runtime-report program below prints the version and installation path of the JVM that is actually executing it. Run it in your terminal and editor to compare them. Paths are machine-specific, so differences are clues, not automatically errors. Do not paste private filesystem paths into public support posts.
Running it on this page reports the lesson sandbox's Java installation, not the JDK on your computer. A successful browser run proves the example works in that sandbox. It does not prove that your local terminal or editor is configured correctly; the local checks are still required.
Main.java · Inspect the running Java environment
Predict the result, edit Main.java, then run your program.
Standard input · optional
Select Run code to compile and execute this program.
Independent lab: prove the setup survives a fresh start
Prove that your toolchain works after a fresh start, not only in the terminal where you repaired it. Keep a short setup note in your practice folder, without passwords or private machine paths you do not want to share.
- Record your operating system, architecture, JDK major version, and editor.
- Open a fresh terminal and record java -version and javac -version.
- Compile and run Main.java from a folder you can identify.
- Change the second printed line to Editor and terminal agree, save, recompile, and verify the changed result.
- Run that same file from the editor and compare the messages.
- Explain why a successful on-page sandbox run does not verify your computer's installation.
Reveal the lab solution and review criteria
Main.java · Editor and terminal agreement
Predict the result, edit Main.java, then run your program.
Standard input · optional
Select Run code to compile and execute this program.
Java setup ready
Editor and terminal agreeThe source changes only the message; no new language feature is needed. Save, compile, and launch again to prove that the changed source—not an older Main.class—is being used. Reopen a terminal and repeat the checks to discover configuration that worked only in a previous session.
Your evidence should contain matching intended compiler/runtime major versions, a known source folder, the changed output from the terminal, and the same changed output from the editor. Do not mark your installation verified solely because this embedded solution runs.
Common setup errors: diagnose before reinstalling
Start with the first failing step. If the terminal cannot find javac, inspect installation and PATH. If it finds javac but not the source file, inspect the folder. If compilation works but launch fails, inspect the class name, classpath, and runtime. These are different problems.
java works, but javac is not found
A runtime alone may be selected, or the compiler's bin directory is not on PATH. Check the package type and resolved paths. Install or select a JDK; do not try to repair this by renaming the source file.
The version is still 17, 25, or another release
The shell is selecting a different installation. Start a new terminal and inspect the command paths. Prefer matching version 21 for this course. Do not uninstall an older JDK that another project needs; select deliberately instead.
JAVA_HOME is set, but java still uses the old version
JAVA_HOME and command lookup are separate. Check whether the intended JDK's bin directory is on PATH and whether an older entry is selected first. On macOS use java_home to confirm the selected installation; on Windows inspect Get-Command; on Linux inspect the resolved alternatives.
error: file not found: Main.java
Check the terminal's current folder and list its files. Verify the source was saved and that the editor did not append .txt. Changing the JDK version will not make a file in a different folder appear.
Could not find or load main class Main
Check that compilation succeeded and Main.class exists in the folder you are launching from. For this package-free example, try java -cp . Main to explicitly use the current folder. Use Main, not Main.class, as the launch target.
UnsupportedClassVersionError or release version 21 not supported
The former often means the selected runtime is older than the compiled class format; the latter means the compiler does not support the requested release. Compare java -version and javac -version and select a compatible pair before recompiling.
VS Code shows no Java Run action
Confirm the Java extension pack is installed and enabled, Main.java is inside an opened folder, and language support has finished initializing. Check the Java runtime configuration and the Output panel. A terminal run that succeeds narrows the issue to editor setup.
Frequently asked questions
Must I uninstall other Java versions?
No. Several JDKs can coexist. Keep versions needed by other projects and select the intended one in the terminal and project settings. Verify both compiler and runtime after changing a selection.
Is JAVA_HOME always required?
Not for the simple javac/java workflow when PATH already finds the correct tools. Some editors and build tools use JAVA_HOME to locate a JDK. Set it to the JDK root when needed, and verify rather than assuming it changes PATH automatically.
Can I use a newer JDK?
The simple examples use language features older than Java 21, but matching the course baseline avoids unnecessary version differences. With a newer compiler, javac --release 21 Main.java targets Java 21 language and class-file compatibility; it does not install a Java 21 runtime or change the editor's selected JDK.
Do I need Docker on my own computer?
No. Docker is used by SovranCode's local-preview runner, not by the ordinary JDK installation instructions in this lesson. Your terminal workflow needs a JDK and source file. On-page execution is separate from your machine's toolchain.
You are ready when these checks pass
- A fresh terminal finds both java and javac at the intended version.
- You can locate Main.java and compile it successfully.
- You can run Main and explain its printed result.
- Changing, saving, and recompiling changes the result as expected.
- Your editor runs the same source with a compatible selected JDK.
You now have a way to distinguish tool setup from program behavior. The next lesson will unpack Java syntax and your first program in detail; there is no need to rush into build systems or frameworks yet.
Is your setup really verified?
Answer all six questions and check the explanations. This is a temporary knowledge check, not an automated inspection of your computer or saved course progress.
Official downloads and references
Instructions and exercises are original SovranCode material. Consult the official instructions for platform-specific changes and package requirements.
- Temurin Java 21 downloads
- Temurin installation documentation
- Ubuntu Java setup
- VS Code Java setup
- VS Code Java runtime configuration
Related learning: Java Introduction · Java course roadmap · Git and GitHub course.
Last updated: