Module: Getting Started

Installation

Getting Started: Installation

Welcome to the first step in our Spring Boot tutorial! This section will guide you through installing the necessary tools to start building Spring Boot applications. We'll cover installing the Java Development Kit (JDK), an Integrated Development Environment (IDE) – we'll use IntelliJ IDEA as an example, but other options are available – and setting up a build tool like Maven or Gradle.

1. Installing the Java Development Kit (JDK)

Spring Boot applications are written in Java, so you'll need the JDK installed on your system. We recommend using a recent, Long-Term Support (LTS) version of Java. As of late 2023, Java 17 and Java 21 are excellent choices.

  • Download: Download the JDK from one of the following sources:

  • Installation: Follow the installation instructions specific to your operating system (Windows, macOS, Linux). Generally, this involves running an installer and accepting the default settings.

  • Verify Installation: Open a terminal or command prompt and run the following command:

    java -version
    

    You should see output similar to:

    java version "17.0.7" 2023-04-18
    Java(TM) SE Runtime Environment (build 17.0.7+8)
    Java HotSpot(TM) 64-Bit Server VM (build 17.0.7+8, mixed mode, sharing)
    

    If you see an error message, double-check your installation and ensure that the java command is in your system's PATH environment variable. (See the "Setting the JAVA_HOME Environment Variable" section below if needed).

  • Setting the JAVA_HOME Environment Variable (Important): Many tools, including Spring Boot, rely on the JAVA_HOME environment variable to locate your JDK installation.

    • Windows:

      1. Search for "Environment Variables" in the Start Menu.
      2. Click "Edit the system environment variables".
      3. Click "Environment Variables...".
      4. Under "System variables", click "New...".
      5. Variable name: JAVA_HOME
      6. Variable value: The path to your JDK installation directory (e.g., C:\Program Files\Java\jdk-17.0.7).
      7. Click "OK" on all windows.
    • macOS/Linux:

      1. Open your shell configuration file (e.g., ~/.bashrc, ~/.zshrc).

      2. Add the following line, replacing /path/to/your/jdk with the actual path:

        export JAVA_HOME=/path/to/your/jdk
        
      3. Save the file and source it:

        source ~/.bashrc  # or source ~/.zshrc
        

2. Installing an Integrated Development Environment (IDE)

While you can write Spring Boot applications with a simple text editor, an IDE significantly improves your development experience. We'll use IntelliJ IDEA Community Edition, which is free and powerful.

  • Download: Download IntelliJ IDEA Community Edition from: https://www.jetbrains.com/idea/download/

  • Installation: Follow the installation instructions for your operating system.

  • Configuration: When you first launch IntelliJ IDEA, you'll be prompted to configure it. Accept the default settings or customize them to your preferences. Ensure that the JDK you installed in the previous step is detected. If not, you'll need to manually configure it in IntelliJ IDEA's settings (File -> Project Structure -> SDKs).

3. Choosing a Build Tool: Maven or Gradle

Spring Boot projects are typically built using either Maven or Gradle. Both are build automation tools that manage dependencies, compile code, and package your application.

  • Maven: A more established and widely used build tool. Uses an XML-based configuration file (pom.xml).
  • Gradle: A more flexible and modern build tool. Uses a Groovy or Kotlin-based Domain Specific Language (DSL) for configuration (build.gradle).

For beginners, Maven is often recommended due to its simpler configuration and larger community support. However, both are viable options.

  • Maven Installation: Maven is usually not pre-installed. You can download it from: https://maven.apache.org/download.cgi

    • Follow the installation instructions on the website.
    • Similar to the JDK, you'll need to set the M2_HOME environment variable and add the Maven bin directory to your PATH.
  • Gradle Installation: Gradle can be downloaded from: https://gradle.org/install/

    • Follow the installation instructions on the website.
  • IntelliJ IDEA Integration: IntelliJ IDEA has excellent support for both Maven and Gradle. It will automatically detect them if they are installed and configured correctly.

Next Steps

Congratulations! You've successfully installed the necessary tools. Now you're ready to move on to the next step: creating your first Spring Boot project. We'll cover that in the following section.