Local Environment Setup
Explore how to prepare your local computer for Java development by installing the Java Development Kit version 21 or higher. Understand how to configure environment variables across Windows macOS and Linux to enable running and compiling Java applications effectively. Verify your installation to ensure your development tools are ready.
Before we can write world-class software, we need the right tools on our workbench. While browser-based editors are great for quick exercises, professional developers build and run applications on their local machines. Setting up this environment is a rite of passage. We will walk through the exact steps needed to get our local computer ready to understand and execute Java code.
Choosing and downloading the JDK
To run Java code, an end user only needs the Java Runtime Environment (JRE). However, to write and compile Java code, developers need the Java Development Kit (JDK). The JDK includes the compiler (javac), the virtual machine (java), and a suite of debugging tools.
When learning how to install java, the first step is selecting a distribution. Oracle maintains the official version, but many organizations prefer open-source builds like Eclipse Temurin (Adoptium) or Amazon Corretto. For this course, any standard JDK version 21 or higher will work perfectly.
When seeking a java development kit for windows, macOS, or Linux, visit the official Adoptium website or Oracle’s download page. Select the installer that matches your operating system and CPU architecture.
Installation on Windows
Installing java in Windows is generally straightforward if we use the provided .msi or .exe installer.
Double-click the downloaded installer file.
Follow the setup wizard prompts.
Pay close attention to the installation path. It usually defaults to
C:\Program Files\Java\jdk-21. We must remember this location for the next step.If the installer offers an option to “Set JAVA_HOME variable” or “Add to PATH”, make sure to select it. This saves us from doing it manually.
Installation on macOS
Developers using macOS can use the provided .pkg installer from the official sites. Alternatively, you can use the Homebrew package manager via the terminal.
brew install openjdk@21
Homebrew typically handles system paths automatically. If it requires manual path linking, the terminal output will provide the exact commands to run.
Installation on Linux
Linux users can rely on their distribution’s package manager. For Debian or Ubuntu-based systems, open the terminal and execute the following commands.
sudo apt updatesudo apt install openjdk-21-jdk
Configuring the environment
If the installer did not automatically configure our system, our terminal will not recognize commands like javac. We must tell the operating system exactly where the Java tools live. To do this, we need to know how to set java environment variable paths.
The most important environment variable is PATH. The operating system searches the directories listed in the PATH variable whenever we type a command in the terminal.
To set this up on Windows:
Open the Start Menu, type “Environment Variables”, and select “Edit the system environment variables”.
Click the “Environment Variables” button at the bottom of the window.
Under “System variables”, click “New” to create a
JAVA_HOMEvariable. Set its value to your JDK installation folder (e.g.,C:\Program Files\Java\jdk-21).Find the
Pathvariable in the same list and click “Edit”.Add a new entry exactly like this:
%JAVA_HOME%\bin.Click OK to save all changes.
On macOS and Linux, configuring the environment is typically done by adding export JAVA_HOME=/path/to/jdk to your ~/.zshrc or ~/.bashrc file.
Verifying the installation
We must verify that our configuration works. We do this by opening a brand new terminal or command prompt window. The window must be new so it loads the updated environment variables.
Type the following commands:
java -versionjavac -version
Line 1: This command checks if the Java Virtual Machine is installed and accessible. It should print out the version number, confirming the runtime is ready.
Line 2: This command checks if the Java compiler is available. It must also print the version number. If it returns an error like “command not found”, the
PATHvariable was not set correctly.
Once both commands return a version number of 21 or higher, our local workbench is fully assembled and ready for code.