SDKMAN Installation Guide
This document uses SDKMAN to manage Java versions, ensuring that all developers use the same Java environment. Below is a guide for installing and configuring SDKMAN on different operating systems.
- 8 min read
- 2026.09.16
SDKMAN is a command-line tool for managing multiple versions of SDKs such as Java. On macOS and Linux, it can be installed with a single `curl` command; on Windows, you’ll need Git Bash or WSL. Once installed, use `sdk install java` to install a version, and place a `.sdkmanrc` file in your project directory to automatically switch versions when entering that directory.
SDKMAN Installation and Configuration Guide
🧠 What is SDKMAN?
SDKMAN is a tool for managing multiple versions of software development kits, particularly different versions of Java. It allows you to easily switch between different JDK versions across projects.
🎯 Why Do You Need SDKMAN?
During development, we often need to work on multiple projects, each of which may use a different version of Java. SDKMAN helps us:
- 🔄 Easily switch between Java versions
- 🛠️ Unify the team’s development environment
- 🚀 Simplify tool installation and management
- 🔧 Resolve version conflicts in Git Hooks
⚙️ Installing SDKMAN
🍎 macOS and Linux
Completed: 打开终端
打开系统终端或 iTerm2
Completed: 运行安装命令
执行 curl 命令下载并安装 SDKMAN
Completed: 完成安装
按照屏幕提示完成安装过程
Current: 重新加载配置
重新加载 shell 配置文件
- Open the terminal 2. Run the installation command:
curl -s "https://get.sdkman.io" | bash
- Follow the on-screen instructions to complete the installation
- Reload the shell configuration:
source "$HOME/.sdkman/bin/sdkman-init.sh"
🪟 Windows
Using Git Bash or MSYS2
Completed: 打开 Git Bash
打开 Git Bash 或 MSYS2 终端
Completed: 运行安装命令
执行 curl 命令下载并安装 SDKMAN
Completed: 完成安装
按照屏幕提示完成安装过程
Current: 重新加载配置
重新加载 shell 配置文件
- Open the Git Bash or MSYS2 terminal 2. Run the installation command:
curl -s "https://get.sdkman.io" | bash
- Follow the on-screen instructions to complete the installation
- Reload the shell configuration:
source "$USERPROFILE/.sdkman/bin/sdkman-init.sh"
Using Windows PowerShell (Alternative)
If you are not using Git Bash or MSYS2, consider using the following tools to install a specific version of Java:
- Scoop - Windows package manager
- Chocolatey - Windows package manager
📦 Installing the Java Version Required for the Project
This project uses Java 8. After installing SDKMAN, run the following commands to install the required Java version:
sdk install java 8.0.452-amzn
View available Java versions
sdk list java
View installed versions
sdk list java | grep installed
Common SDKMAN Commands
| Command | Description |
|---|
| sdk list java | View all available Java versions | | sdk install java <version> | Install a specific Java version | | sdk use java <version> | Temporarily switch to a specific version | | sdk default java <version> | Set the default Java version | | sdk current java | View the currently used Java version | | sdk uninstall java <version> | Uninstall a specific Java version |
✅ Verify Installation
After installation, you can run the following commands to verify that SDKMAN is working properly:
sdk version
Verify that the Java version is correct:
java -version
The expected output should look like this:
openjdk version "1.8.0_452"
OpenJDK Runtime Environment (build 1.8.0_452-b08)
OpenJDK 64-Bit Server VM (build 25.452-b08, mixed mode)
🔄 Automatic Java Version Switching for Projects
This project includes a .sdkmanrc file that automatically switches to the correct Java version when you enter the project directory. To enable this feature, run:
sdk env
Example Project Configuration File
Create a .sdkmanrc file in the project root directory:
# This file is used by SDKMAN to automatically switch to the correct Java version
# when entering this project directory
#
# 注意:
# 1. 此文件需要 SDKMAN 支持才能生效
# 2. 如果您没有安装 SDKMAN,请参考本文档进行安装
# 3. Windows 用户需要在 Git Bash 或类似的 Unix-like 环境中使用 SDKMAN
# 4. 如果您使用的是 IDE(如 IntelliJ IDEA),请确保在项目设置中也配置了正确的 JDK
java=8.0.452-amzn
🔧 Troubleshooting
Java Version Issues with Git Hooks
If you encounter Java version-related issues when running Git commands, please ensure:
- ✅ SDKMAN is installed correctly
- ✅ The Java version required by the project is installed
- ✅ SDKMAN has been loaded in your shell configuration file (such as
.bashrc,.zshrc, or.bash_profilefor Git Bash)
Windows-Specific Issues
On Windows, if you use Git in CMD or PowerShell, you may need to manually set the JAVA_HOME environment variable to point to the correct Java version.
Set the JAVA_HOME Environment Variable
# PowerShell 示例
$env:JAVA_HOME = "C:\Users\YourUsername\.sdkman\candidates\java\8.0.452-amzn"
Set the Environment Variable Permanently
# 设置系统环境变量(需要管理员权限)
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Users\YourUsername\.sdkman\candidates\java\8.0.452-amzn", "User")
Troubleshooting
SDKMAN 命令未找到
sdk: command not found
- /usr/bin:/bin:/usr/sbin:/sbin
- SDKMAN 未正确安装
- shell 配置文件未重新加载
- 需要重启终端或重新加载配置
Solution: Make sure you have reloaded your shell configuration or restarted the terminal
Java 版本未自动切换
Java version not switched automatically
- Project directory
- .sdkmanrc 文件不存在或格式错误
- SDKMAN 未正确加载
- 需要运行 sdk env 命令
Solution: Run the sdk env command, or check if the .sdkmanrc file exists
Windows Git hooks 失败
Git hooks failed on Windows
- CMD/PowerShell environment
- 在 CMD 或 PowerShell 中运行 Git
- 环境变量配置不正确
- 建议使用 Git Bash
Solution: Use Git Bash instead of CMD or PowerShell
📚 Related Resources
Official Documentation
Related Blog Posts
- Git Hooks and Multi-JDK Environment Issues - Resolving Java version conflicts in Git Hooks
- Git Hooks and Node Environment Issues - Resolving Node.js environment issues in Git Hooks
- Git Configuration Management for Multiple Environments - Managing Git Configurations Across Multiple Environments
Recommended Tools
- Scoop - Windows Package Manager
- Chocolatey - Windows Package Manager
- Husky - Git hooks tool
- NVM - Node.js version manager