AlgoMaster Logo

Setting Up Environment

Low Priority17 min readUpdated June 5, 2026
Listen to this chapter
Unlock Audio

Before you write a single line of Java, your machine needs a JDK installed and an editor that understands it. By the end of this lesson, java -version will print a real version string in your terminal, and you'll have an IDE open and ready.

This chapter only covers setup. Here, you just install one.

The Setup Flow

The process is short. Pick a JDK, install it, set up JAVA_HOME and PATH if the installer didn't, verify it works, then install an IDE.

Take the steps in order and don't skip the verification one. A common cause of "Java doesn't work" is a terminal that was opened before the installer finished writing the PATH.

Pick a JDK Distribution

A JDK is the compiler, runtime, and standard library together. Several companies ship their own builds of it, all based on the same upstream open-source project called OpenJDK. They behave the same for almost everything a learner will do. The choice mostly comes down to license terms and who's supplying the binaries.

The safe default is Eclipse Temurin from the Adoptium project. It's free, widely used in production, and ships builds for macOS, Windows, and Linux on both Intel and ARM.

The common alternatives:

DistributionVendorLicenseNotes
Eclipse TemurinAdoptium (Eclipse Foundation)GPL with Classpath ExceptionRecommended default. Replaced AdoptOpenJDK in 2021.
Oracle JDKOracleOracle NFTC for current LTSFree for development and most production use under the NFTC license.
Amazon CorrettoAmazonGPL with Classpath ExceptionUsed heavily inside AWS, free for all use.
Azul ZuluAzul SystemsGPL with Classpath ExceptionFree Community edition, lots of older-version builds.

Pick Temurin unless your team already standardized on one of the others.

Pick a Java Version

Java releases a new version every six months, but most of those are short-lived. Every few years, one release gets the LTS label, which stands for Long-Term Support. LTS versions get security patches and bug fixes for years, which is why companies build on them.

Use Java 21 or Java 25, the two newest LTS releases. Java 17 is also a fine choice if a project you're working with hasn't moved off it yet. Avoid non-LTS versions like 22, 23, or 24 for learning, because tutorials, libraries, and Stack Overflow answers all tend to assume an LTS.

Why does this matter? Two reasons. First, some language features only exist in certain versions. Pattern matching for switch landed in Java 21. Records arrived in Java 16. If you pick Java 11 because it was on an old machine, half of the modern Java syntax in this course won't compile. Second, sample code from a blog post written this year almost certainly expects 21, 25, or 17.

Install on macOS

On macOS you have two reasonable paths: download the official Temurin installer, or use Homebrew.

Option 1: the `.pkg` installer. Visit , pick the Temurin 21 (LTS) build for macOS, and choose the right architecture. If your Mac has an Apple Silicon chip (M1, M2, M3, M4), pick the aarch64 package. If it's an older Intel Mac, pick x64. Download the .pkg, double-click it, and follow the installer. It places the JDK under /Library/Java/JavaVirtualMachines/.

Option 2: Homebrew. If you already use Homebrew, this is a one-liner:

After either path finishes, list the JDKs macOS knows about:

That last path is what JAVA_HOME should point to.

If you ever have several JDKs installed at once, you can ask java_home for a specific version:

The path it prints is the one to use.

Install on Windows

On Windows, download the Temurin 21 .msi installer from . Pick the x64 build unless you're on an ARM Windows machine, in which case pick the ARM build.

Run the installer. On one of the screens, the installer asks whether to set JAVA_HOME and add java to PATH. Check both boxes. This single click saves a lot of trouble.

After the installer finishes, close any open terminal or PowerShell windows, then open a new one. Environment variables set by an installer aren't picked up by terminals that were already running. This is the most common reason a fresh install seems broken.

In the new PowerShell window:

If all three print something sensible, you're done. If they don't, jump to the Common Issues section at the end.

Install on Linux

On Linux, your package manager is usually the simplest path.

Debian or Ubuntu:

Fedora, RHEL, or CentOS Stream:

The -devel package matters. The non-devel package only installs the JRE, which can run Java code but can't compile it. Without it, javac won't exist.

If you'd rather have multiple Java versions side by side (useful when working across projects that pin different versions), use SDKMAN:

The -tem suffix tells SDKMAN to grab Temurin. SDKMAN handles JAVA_HOME and PATH for you and lets you switch versions with sdk use java <version>.

Set JAVA_HOME and PATH

JAVA_HOME is an environment variable that points to the root of your JDK install. Lots of tools (build tools like Maven and Gradle, IDEs, scripts) read it to find Java. PATH is the list of directories your shell searches when you type a command, and it needs to include the JDK's bin directory so that typing java or javac works from anywhere.

On Windows, if you checked the boxes in the installer, both are already set. On macOS and Linux, you'll usually want to set them yourself in your shell profile.

macOS (zsh, the default since Catalina). Edit ~/.zshrc:

The $(/usr/libexec/java_home -v 21) part runs that command and substitutes its output. That way, you don't have to hardcode the JDK path. Reload the shell with source ~/.zshrc or just open a new terminal tab.

Linux (bash). Edit ~/.bashrc (or ~/.profile on some setups):

The exact path depends on your distribution. On Debian/Ubuntu it's usually under /usr/lib/jvm/. Run ls /usr/lib/jvm/ to confirm the directory name and copy that into the export. After editing, run source ~/.bashrc.

Windows (PowerShell, persistent). From an elevated PowerShell prompt:

Replace the path with the actual install location if yours is different. Close the PowerShell window after running these and open a fresh one for the changes to take effect.

Verify the Install

Three commands tell you whether everything is wired up correctly.

The version number and the word "Temurin" are the markers to look for. Corretto and Zulu installs print those names instead. The middle line shows the runtime; the third line shows the VM.

javac is the compiler. It's part of the JDK, not the JRE. If java works but javac says "command not found", you installed the JRE by mistake. Install the JDK package and try again.

(On Windows, run echo $env:JAVA_HOME in PowerShell.) The exact path varies, but it should end somewhere inside a directory whose name has 21 in it.

If the version that java -version prints doesn't match what javac -version prints, your PATH is picking up a java from one install and a javac from another. We'll fix that in the Common Issues section.

Pick an IDE

A plain text editor plus javac and java is enough to compile and run code. But for any project beyond a one-file demo, an IDE pays for itself within the first hour. It catches errors as you type, autocompletes class and method names, jumps you to definitions, and handles the build for you.

Three IDEs dominate Java work:

CriteriaIntelliJ IDEA CommunityVS Code + Extension Pack for JavaEclipse
CostFreeFreeFree
Best forBeginners and most Java workPolyglot devs already on VS CodeLegacy enterprise codebases
StrengthsBest Java tooling, smart refactoring, intuitive UILightweight, great if you use VS Code for other languagesLong history, used in big enterprise shops
WeaknessesUses more memory than VS CodeJava support is good but not as deep as IntelliJUI feels dated, steeper learning curve
Recommended for this course?YesYes, as a lighter alternativeOnly if you already know it

If you're new to Java, install IntelliJ IDEA Community Edition. The "Community" part is important; it's the free version. The paid Ultimate edition adds features for Spring, JavaScript, and database tooling, but you don't need any of that yet.

IntelliJ IDEA Community

Download it from . Scroll past the Ultimate section to find Community. Install and launch.

On first launch, IntelliJ asks if you want to create a new project. Click New Project. Set the name to MyShop. For the JDK dropdown, IntelliJ should auto-detect the Temurin 21 install you just made. If it doesn't, click Add JDK and point it at the path that JAVA_HOME holds. Leave the build system as IntelliJ (instead of Maven or Gradle) for now. Click Create.

IntelliJ opens the project. A src folder appears on the left. That's where Java source files go.

VS Code with Extension Pack for Java

If you already use VS Code, install Microsoft's Extension Pack for Java. Open VS Code, hit the Extensions icon, search for "Extension Pack for Java", and install. It bundles six extensions, including the language server, debugger, and test runner.

VS Code in Java mode works differently from IntelliJ. There's no "create new project" wizard for plain Java. Instead, you make an empty folder named MyShop somewhere on disk, open it in VS Code (File > Open Folder), and start adding .java files inside it. The extension pack picks them up automatically and sets up everything in the background.

You can confirm Java is wired up by opening the Command Palette (Cmd+Shift+P on macOS, Ctrl+Shift+P elsewhere) and running Java: Configure Java Runtime. It shows the JDKs it detected.

Eclipse

Eclipse is still around, and plenty of older codebases assume it. If you have a specific reason to use it (a job that requires it, a course that uses it, or familiarity), download the Eclipse IDE for Java Developers from . For most readers of this course, IntelliJ Community is the better starting point.

Common Issues and Fixes

Even with everything done right, three problems show up often. Knowing how to recognize them saves time.

Problem 1: `command not found: java` after install.

You ran the installer, but a fresh java -version says the command doesn't exist.

Two causes. First, the terminal window was open before the installer added java to PATH. Close it and open a new one. Second, on macOS and Linux, the installer might not edit your shell profile. Open ~/.zshrc (or ~/.bashrc) and confirm there's an export PATH=$JAVA_HOME/bin:$PATH line. If not, add it and run source ~/.zshrc.

On Windows, this often means the installer didn't get permission to update PATH. Reinstall the .msi and make sure to check the "Set JAVA_HOME" and "Add to PATH" boxes.

Problem 2: `java -version` shows one version, `javac -version` shows another.

Example:

This means your machine has multiple Java installs and PATH points to one for java and another for javac. Run which java and which javac (or where java on Windows) to see the actual paths. Whichever one is wrong, fix it by reordering PATH so that the correct JDK's bin directory comes first.

On macOS, the cleanest fix is to anchor JAVA_HOME to a specific version:

On Linux, the system-wide way is update-alternatives:

Both commands show a numbered list of installed Javas. Pick the one matching your target version.

Problem 3: IDE can't find a JDK.

You opened IntelliJ or VS Code, and it complains that no JDK is configured. The OS knows about your JDK (java -version works in the terminal), but the IDE doesn't.

In IntelliJ: File > Project Structure > Project > SDK. Click Add SDK > JDK and point it at the path stored in JAVA_HOME. On macOS, that's typically something like /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home. Find yours by running echo $JAVA_HOME in the terminal.

In VS Code: run Java: Configure Java Runtime from the Command Palette. If your JDK isn't listed, click the install link or set the java.jdt.ls.java.home setting to the JDK path manually.