Getting Started with Java: Installing JDK and Setting Up Your Environment
Last updated on August 12, 2025 by Troy.
Java has been one of the most reliable and widely used programming languages for decades. From enterprise-level backend systems to Android applications, it powers millions of solutions worldwide. When I first decided to dive into Java programming, the very first step I had to take was to set up the development environment. Without that, writing and running Java code would be impossible. Setting up Java involves more than just downloading files. It’s about preparing your system so that you can seamlessly write, compile, and execute your programs without interruptions.
In this guide, I’ll walk through the exact steps I take to install the Java Development Kit (JDK) and set up the right environment for smooth development. I’ll also share tips from my own experience so that you can avoid the small but frustrating mistakes many beginners make. By the end of this, you’ll be ready to start coding your first Java application without having to troubleshoot unnecessary setup issues.
Installing the Java Development Kit (JDK)
Before writing any Java code, you need the JDK. This package contains all the tools necessary for compiling and running Java programs. It includes the Java compiler (javac
), the Java Runtime Environment (JRE), and other utilities that are essential for development.
Downloading the JDK
I start by visiting the official Oracle website or the OpenJDK site to download the correct version of the JDK. For most people, the latest Long-Term Support (LTS) version is ideal. LTS releases receive extended updates and security patches, which means fewer compatibility issues down the line. The download page usually asks for your operating system. Windows, macOS, or Linux, and I make sure to select the one that matches my machine.
It’s important to know whether you’re running a 32-bit or 64-bit version of your operating system, especially on older systems. Most modern computers are 64-bit, so I go for that option unless there’s a specific requirement for a 32-bit setup.
Installing on Windows
On Windows, the JDK download comes as an installer package. I simply double-click the file and follow the prompts. During installation, I always take note of the installation path, usually something like C:\Program Files\Java\jdk-<version>
. This location will be useful later when setting up environment variables.
One thing I never skip is enabling the option to set the JAVA_HOME
variable automatically if the installer offers it. It saves a step, although I still double-check it later.
Installing on macOS
For macOS, the JDK is provided as a .dmg
file. I open it and follow the simple installation steps. Once installed, the JDK files typically reside in /Library/Java/JavaVirtualMachines/
. From there, I can verify the installation by opening Terminal and typing:
java -version
This command confirms the installed version of Java and ensures everything is functioning.
Installing on Linux
On Linux, installing the JDK can be as simple as running a few commands in the terminal. For Ubuntu or Debian-based systems, I usually run:
sudo apt update
sudo apt install default-jdk
For Fedora or CentOS, I use:
sudo dnf install java-latest-openjdk
If I want a specific version, I search the repositories or download from the official OpenJDK site and follow the manual installation instructions.
Setting Up Environment Variables
After installing the JDK, the next crucial step is setting up environment variables so that Java commands can run from any terminal or command prompt window without navigating to the JDK directory.
Setting JAVA_HOME on Windows
On Windows, I go to the System Properties panel. From there, I click Advanced system settings, then Environment Variables. Under system variables, I create a new variable named JAVA_HOME
and set its value to the JDK installation path.
Next, I locate the Path
variable in the system variables section and edit it. I add a new entry:
perl %JAVA_HOME%\bin
This ensures that the system can find the Java compiler and runtime tools without needing their full path.
Setting JAVA_HOME on macOS and Linux
On macOS and Linux, I open my shell configuration file, such as .bash_profile
, .zshrc
, or .bashrc
, and add:
bash export JAVA_HOME=/path/to/jdk
export PATH=$JAVA_HOME/bin:$PATH
I replace /path/to/jdk
with the actual JDK directory path. After saving the file, I run:
bash source ~/.zshrc
or
bash source ~/.bashrc
This refreshes the environment so that the changes take effect immediately.
Verifying the Installation
To check that everything works as expected, I open a terminal or command prompt and type:
java -version
javac -version
If both commands display version information, it means the JDK is installed correctly and the environment variables are set up properly.
Installing an Integrated Development Environment (IDE)
While Java code can be written in any text editor, I find using an IDE makes the process much smoother. It offers features like code completion, debugging tools, and project management.
IntelliJ IDEA
IntelliJ IDEA is my go-to choice for Java development. The Community Edition is free and more than capable for most projects. Installing it is straightforward, download the installer from JetBrains’ website, run it, and follow the prompts. Once opened, I can create a new Java project and start coding immediately.
Eclipse
Eclipse is another popular option, especially for enterprise projects. It’s open-source and highly customizable. The installation process involves downloading the installer, running it, and selecting the “Eclipse IDE for Java Developers” package. I like Eclipse when I need lots of plugins for specific frameworks.
NetBeans
NetBeans is officially supported by Oracle and is particularly friendly for beginners. It’s easy to install and integrates well with the JDK. It also offers built-in support for other languages like PHP and HTML, making it versatile for full-stack projects.
Writing and Running Your First Java Program
After setting up the environment, the fun part begins, writing and running Java code. I usually start with the classic “Hello, World!” program to test everything.
In my IDE, I create a new Java class:
java public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
I then run the program directly from the IDE. If I’m not using an IDE, I save the file as HelloWorld.java
, open a terminal, and type:
javac HelloWorld.java
java HelloWorld
If “Hello, World!” appears on the screen, I know the environment is fully operational.
Common Issues and How I Solve Them
Even with clear instructions, I’ve run into a few common problems.
PATH or JAVA_HOME Not Set Correctly
If typing java -version
returns an error, I double-check my environment variables. Sometimes the installation path has a version number in it, and if I upgrade the JDK later, I need to update the JAVA_HOME
variable.
Multiple Java Versions
Having multiple versions of Java installed can cause conflicts. I make sure the version I want to use is the one set in JAVA_HOME
and appears first in the PATH
.
Permission Issues on macOS or Linux
On Unix-based systems, permission errors sometimes occur if the JDK is installed in a directory that requires elevated access. Running commands with sudo
during installation usually fixes this.
Preparing for Real Projects
With Java installed and the environment ready, I can move on to more complex projects. I often organize my projects into separate folders and use build tools like Maven or Gradle to manage dependencies and compile code. These tools integrate seamlessly with most IDEs and save time when working on larger applications.
I also make it a habit to explore Java documentation regularly. It’s a rich resource that helps me understand the standard library, learn new classes, and discover built-in methods that save me from writing extra code.
Conclusion
Getting Started with Java requires more than just enthusiasm. It is about methodically setting up the tools that will allow your creativity and logic to flow into working code. Installing the JDK, configuring environment variables, and selecting a comfortable IDE lay the foundation for your programming journey. Once this is done, writing and running Java applications becomes a smooth and rewarding process.
For me, the setup phase is like preparing a workspace before starting a project. The better the preparation, the more enjoyable and efficient the work that follows. With your environment ready, you can now focus on learning Java’s syntax, exploring its object-oriented principles, and building applications that bring your ideas to life.