Install Temurin 21 LTS on Windows; the installer writes JAVA_HOME automatically
winget install EclipseAdoptium.Temurin.21.JDKSet up Java: install Temurin/OpenJDK, switch versions with SDKMAN, configure JAVA_HOME, switch Maven and Gradle repositories, scaffold projects and fix common errors.
Install Temurin 21 LTS on Windows; the installer writes JAVA_HOME automatically
winget install EclipseAdoptium.Temurin.21.JDKInstall JDK 21 with Homebrew on macOS or the Adoptium repo on Ubuntu
# macOS
brew install --cask temurin@21
# Ubuntu / Debian
sudo apt update && sudo apt install -y temurin-21-jdkInstall the JDK with SDKMAN on macOS/Linux so versions can be switched with one command
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 21.0.4-temSDKMAN does not officially support Windows; use winget or WSL instead
List available versions, switch for the session and set the default JDK
sdk list java
sdk use java 17.0.12-tem
sdk default java 21.0.4-temInstall Maven and confirm which JDK it detects
winget install Apache.Maven
mvn -vInstall Gradle; the output also shows the JVM version in use
winget install Gradle.Gradle
# macOS
brew install gradle
gradle -vAdd this to the mirrors section of ~/.m2/settings.xml so Maven resolves everything from Aliyun
<mirror>
<id>aliyun</id>
<mirrorOf>*</mirrorOf>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>Show the merged effective settings to confirm the mirror is loaded
mvn help:effective-settingsPoint the repositories block in build.gradle.kts at the Aliyun mirror
repositories {
maven { url = uri("https://maven.aliyun.com/repository/public") }
}Temporarily skip SSL verification for self-signed corporate certificates; intranet only
mvn -Dmaven.wagon.http.ssl.insecure=true clean packageRoute the JVM through a proxy to debug dependency downloads and outbound timeouts
java -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=7890 -jar app.jarSet JAVA_HOME on Windows and append its bin directory to PATH
# Windows(永久生效,需重开终端)
setx JAVA_HOME "C:\Program Files\Eclipse Adoptium\jdk-21"
setx PATH "%JAVA_HOME%\bin;%PATH%"Never overwrite PATH; append to the existing value or system commands break
Resolve the JDK with java_home on macOS, then persist it in the shell profile
# macOS / Linux
echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 21)' >> ~/.zshrc
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.zshrcConfirm the effective JAVA_HOME first when multiple JDKs conflict
echo %JAVA_HOME%
# macOS / Linux
echo $JAVA_HOMEMaven prints both the Java version and JAVA_HOME, the quickest consistency check
mvn -versionVerify the runtime and compiler match; mismatches mean PATH points at another JDK
java -version
javac -versionGenerate a project with the standard Maven layout from an archetype
mvn archetype:generate -DgroupId=com.demo -DartifactId=demo -DinteractiveMode=falsePackage and run the artifact to verify the whole build chain
mvn clean package
java -jar target/demo-1.0-SNAPSHOT.jarInitialize a Java application project with Gradle
gradle init --type java-applicationOpen the built-in interactive shell to quickly verify syntax and API behavior
jshellInstall the Java extension pack (debug, test, dependency tooling) and the language server in VS Code
code --install-extension vscjava.vscode-java-pack
code --install-extension redhat.javaInstall the free IntelliJ IDEA Community edition on Windows; use brew --cask on macOS
winget install JetBrains.IntelliJIDEA.CommunityManage Maven and Gradle versions with SDKMAN so the team stays consistent
sdk install maven
sdk install gradleWith several JDKs installed, check which one the command actually resolves to
where java
# macOS / Linux
which -a javaPrint the JVM java.home to catch a JAVA_HOME pointing at the wrong directory
java -XshowSettings:properties -version 2>&1 | findstr java.homeForce a refresh of SNAPSHOT dependencies from the remote repository
mvn -U clean installTrace dependency conflicts to find multiple versions of the same library
mvn dependency:tree -Dincludes=org.slf4jDelete the corrupted artifact directory and re-resolve it
rm -rf ~/.m2/repository/com/demoCheck the default max heap when startup fails in a memory-limited container
java -XX:+PrintFlagsFinal -version | findstr MaxHeapSizeThis website uses cookies to ensure you get the best experience on our website. Privacy Policy.