Module: Getting Started

Environment Setup

Getting Started - Environment Setup

Welcome to the first step in your Spring Boot journey! Before we start building amazing applications, we need to set up our development environment. This guide will walk you through everything you need to get started.

Prerequisites

Before diving in, ensure you have the following installed on your system:

  • Java Development Kit (JDK): Spring Boot requires a Java runtime environment. We recommend using JDK 17 or later. You can download it from Oracle or, preferably, a distribution like Adoptium Temurin (formerly AdoptOpenJDK) which is free and open-source.
  • Integrated Development Environment (IDE): While you can use a text editor, an IDE significantly improves your development experience. Popular choices include:
  • Build Tool: Spring Boot commonly uses build tools to manage dependencies and build your application. We'll be using Maven in this tutorial. Maven is usually bundled with most IDEs, but you can also download and install it separately from https://maven.apache.org/.
  • (Optional) Git: Version control is highly recommended. If you're not familiar with Git, consider learning the basics. https://git-scm.com/

1. Installing the JDK

  1. Download: Download the appropriate JDK version for your operating system from Oracle or Adoptium Temurin. Adoptium Temurin is generally preferred for its licensing and community support.

  2. Installation: Follow the installation instructions provided with the downloaded package.

  3. Verify Installation: Open your terminal or command prompt and run:

    java -version
    

    You should see output similar to:

    openjdk version "17.0.7" 2023-01-17
    OpenJDK Runtime Environment (build 17.0.7+7-Ubuntu-120.04)
    OpenJDK 64-Bit Server VM (build 17.0.7+7-Ubuntu-120.04, mixed mode, sharing)
    

    If you see an error, double-check your installation and ensure the java command is in your system's PATH environment variable.

2. Setting up your IDE

The setup process varies slightly depending on your chosen IDE. Here's a quick overview for each:

  • IntelliJ IDEA:
    • IntelliJ IDEA usually auto-detects your JDK installation. If not, go to File > Project Structure > SDKs and add your JDK.
    • Ensure the Maven integration is enabled (File > Settings > Build, Execution, Deployment > Build Tools > Maven).
  • Eclipse:
    • Go to Window > Preferences > Java > Installed JREs and add your JDK.
    • Ensure Maven is installed and configured. Eclipse may prompt you to install it during project creation.
  • VS Code:
    • Install the "Java Extension Pack" from the VS Code Marketplace. This pack includes essential Java development tools, including support for Maven.
    • Configure the Java runtime by setting the java.home setting in your VS Code settings (File > Preferences > Settings, search for java.home).

3. Verifying Maven Installation

  1. Open a terminal or command prompt.

  2. Run:

    mvn -version
    

    You should see output displaying the Maven version and other configuration details. If you get an error, ensure Maven is installed correctly and the mvn command is in your system's PATH environment variable.

4. Setting Environment Variables (Important!)

Setting environment variables is crucial for Maven and Java to work correctly. Specifically, you need to ensure:

  • JAVA_HOME: Points to the root directory of your JDK installation. For example: /usr/lib/jvm/java-17-openjdk-amd64 (Linux/macOS) or C:\Program Files\Java\jdk-17 (Windows).
  • MAVEN_HOME: Points to the root directory of your Maven installation (if you installed it separately).
  • PATH: Includes the bin directories of both your JDK and Maven installations. This allows you to run java, javac, and mvn commands from any directory.

How to set environment variables:

  • Windows: Search for "Environment Variables" in the Start Menu. Edit the system environment variables.

  • macOS/Linux: Edit your shell's configuration file (e.g., .bashrc, .zshrc). Add lines like:

    export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
    export MAVEN_HOME=/opt/apache-maven-3.8.6
    export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
    

    Remember to source the file after making changes (e.g., source ~/.bashrc or source ~/.zshrc).

Congratulations!

You've successfully set up your development environment for Spring Boot. You're now ready to move on to the next step: creating your first Spring Boot project! Let's get coding!