Linux Mint 18.3环境下无法为IntelliJ IDEA配置SDK求助
Hey there! Let's get that Java SDK issue sorted out in IntelliJ—Linux can be a bit trickier than Windows when it comes to registering JDKs, but it's totally manageable.
First, let's confirm exactly where your OpenJDK 1.8 is installed on your system. Open up a terminal and run this command:
update-alternatives --list java
You'll get an output like this (yours might be slightly different):
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
The actual JDK root directory is this path minus the /jre/bin/java part—so in this example, it's /usr/lib/jvm/java-8-openjdk-amd64. Jot that down, we'll need it for IntelliJ.
Next, let's configure IntelliJ to recognize this SDK:
For a new project
- When creating a new project in IntelliJ, look at the "Project SDK" dropdown at the top of the window.
- Click "Add SDK" > "JDK", then navigate to the JDK root directory you noted earlier.
- IntelliJ will automatically detect the Java 1.8 version—select it and proceed with your project setup.
For an existing project
- Open the Project Structure window by pressing
Ctrl+Alt+Shift+S, or go to File > Project Structure. - In the left sidebar, select Project Settings > Project.
- Next to "Project SDK", click the dropdown and choose "New..." > "JDK".
- Navigate to your JDK root directory, select it, and apply the changes.
- While you're here, head to the Modules tab in Project Structure and make sure each module's SDK matches the Project SDK you just set—this avoids inconsistencies.
Quick extra tip
If you use Maven for builds, double-check that IntelliJ is using the correct JDK for Maven:
- Go to File > Settings > Build, Execution, Deployment > Build Tools > Maven > Runner.
- Under "JRE", select the same Java 1.8 SDK you just configured.
That should resolve the "Project SDK is not defined" error. Let me know if you hit any snags along the way!
内容的提问来源于stack exchange,提问作者Vas Mátyás

