10. Installing Spring Boot

Spring Boot can be used with “classic” Java development tools or installed as a command
line tool. Regardless, you will need Java SDK v1.6 or higher. You
should check your current Java installation before you begin:

$ java -version

If you are new to Java development, or if you just want to experiment with Spring Boot
you might want to try the Spring Boot CLI first,
otherwise, read on for “classic” installation instructions.

Tip

Although Spring Boot is compatible with Java 1.6, if possible, you should consider
using the latest version of Java.

10.1 Installation instructions for the Java developer

You can use Spring Boot in the same way as any standard Java library. Simply include the
appropriate spring-boot-*.jar files on your classpath. Spring Boot does not require
any special tools integration, so you can use any IDE or text editor; and there is
nothing special about a Spring Boot application, so you can run and debug as you would
any other Java program.

Although you could just copy Spring Boot jars, we generally recommend that you use a
build tool that supports dependency management (such as Maven or Gradle).

10.1.1 Maven installation

Spring Boot is compatible with Apache Maven 3.2 or above. If you don’t already have Maven
installed you can follow the instructions at maven.apache.org.

Tip

On many operating systems Maven can be installed via a package manager. If you’re an
OSX Homebrew user try brew install maven. Ubuntu users can run
sudo apt-get install maven.

Spring Boot dependencies use the org.springframework.bootgroupId. Typically your
Maven POM file will inherit from the spring-boot-starter-parent project and declare
dependencies to one or more “Starters”. Spring Boot also provides an optional
Maven plugin to create
executable jars.

The spring-boot-starter-parent is a great way to use Spring Boot, but it might
not be suitable all of the time. Sometimes you may need to inherit from a different
parent POM, or you might just not like our default settings. See
Section 13.2.2, “Using Spring Boot without the parent POM” for an alternative solution that uses an import
scope.

10.1.2 Gradle installation

Spring Boot is compatible with Gradle 2 (2.9 or later) and Gradle 3. If you don’t already
have Gradle installed you can follow the instructions at www.gradle.org.

Spring Boot dependencies can be declared using the org.springframework.bootgroup.
Typically your project will declare dependencies to one or more
“Starters”. Spring Boot
provides a useful Gradle plugin
that can be used to simplify dependency declarations and to create executable jars.

Gradle Wrapper

The Gradle Wrapper provides a nice way of “obtaining” Gradle when you need to build a
project. It’s a small script and library that you commit alongside your code to bootstrap
the build process. See docs.gradle.org/2.14.1/userguide/gradle_wrapper.html for details.

10.2 Installing the Spring Boot CLI

The Spring Boot CLI is a command line tool that can be used if you want to quickly
prototype with Spring. It allows you to run Groovy scripts,
which means that you have a familiar Java-like syntax, without so much boilerplate code.

You don’t need to use the CLI to work with Spring Boot but it’s definitely the quickest
way to get a Spring application off the ground.

10.2.1 Manual installation

You can download the Spring CLI distribution from the Spring software repository:

Once downloaded, follow the INSTALL.txt
instructions from the unpacked archive. In summary: there is a spring script
(spring.bat for Windows) in a bin/ directory in the .zip file, or alternatively you
can use java -jar with the .jar file (the script helps you to be sure that the
classpath is set correctly).

10.2.2 Installation with SDKMAN!

SDKMAN! (The Software Development Kit Manager) can be used for managing multiple versions of
various binary SDKs, including Groovy and the Spring Boot CLI.
Get SDKMAN! from sdkman.io and install Spring Boot with

10.2.3 OSX Homebrew installation

If you are on a Mac and using Homebrew, all you need to do to install
the Spring Boot CLI is:

$ brew tap pivotal/tap
$ brew install springboot

Homebrew will install spring to /usr/local/bin.

Note

If you don’t see the formula, your installation of brew might be out-of-date.
Just execute brew update and try again.

10.2.4 MacPorts installation

If you are on a Mac and using MacPorts, all you need to do to
install the Spring Boot CLI is:

$ sudo port install spring-boot-cli

10.2.5 Command-line completion

Spring Boot CLI ships with scripts that provide command completion for
BASH and
zsh shells. You can source the script (also named
spring) in any shell, or put it in your personal or system-wide bash completion
initialization. On a Debian system the system-wide scripts are in /shell-completion/bash
and all scripts in that directory are executed when a new shell starts. To run the script
manually, e.g. if you have installed using SDKMAN!

It will take some time when you first run the application as dependencies are
downloaded. Subsequent runs will be much quicker.

Open localhost:8080 in your favorite web browser and you should see the following
output:

Hello World!

10.3 Upgrading from an earlier version of Spring Boot

If you are upgrading from an earlier release of Spring Boot check the “release notes”
hosted on the project wiki. You’ll find upgrade instructions along with
a list of “new and noteworthy” features for each release.