This guide walks you through setting up a Java game development environment on Ubuntu, covering essential tools, libraries, and steps to start building 2D/3D games. Whether you’re a beginner or transitioning from another platform, these steps will help you establish a smooth workflow.
A JDK is the foundation of Java development, providing the compiler (javac
) and runtime (java
) needed to build and execute Java programs. For game development, OpenJDK 11+ (LTS versions like 17 or 21) is recommended for stability and compatibility with modern libraries.
sudo apt update && sudo apt upgrade -y
sudo apt install openjdk-17-jdk -y
java -version
and javac -version
in the terminal. You should see output like:openjdk version "17.0.11" 2024-10-15
OpenJDK Runtime Environment (build 17.0.11+9-Ubuntu-0ubuntu2.24.04)
OpenJDK 64-Bit Server VM (build 17.0.11+9-Ubuntu-0ubuntu2.24.04, mixed mode)
Setting JAVA_HOME
ensures tools like Maven/Gradle and IDEs can locate your JDK.
sudo update-alternatives --config java
and copy the path before /bin/java
(e.g., /usr/lib/jvm/java-17-openjdk-amd64
).~/.bashrc
(or ~/.zshrc
for zsh):nano ~/.bashrc
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
export PATH="$JAVA_HOME/bin:$PATH"
source ~/.bashrc
echo $JAVA_HOME
—it should return your JDK path.An IDE streamlines coding, debugging, and project management. For Java game development, these are top choices:
sudo snap install intellij-idea-community --classic
sudo snap install eclipse --classic
Build tools automate dependency management and compilation. For game projects (especially larger ones), Maven or Gradle is essential.
sudo apt install maven -y
Verify with mvn -version
.
sudo apt install gradle -y
Verify with gradle -version
.
Game development requires libraries for graphics, input handling, and audio. Here are must-haves:
<!-- Maven dependency for LibGDX -->
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx</artifactId>
<version>1.13.1</version>
</dependency>
<!-- Maven dependency for LWJGL -->
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>3.4.2</version>
</dependency>
Let’s create a basic 2D game using JavaFX (for simplicity).
Main.java
):import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
Pane root = new Pane();
Rectangle rect = new Rectangle(50, 50, 50, 50);
rect.setFill(Color.BLUE);
// Move rectangle with arrow keys
rect.setOnKeyPressed(event -> {
switch (event.getCode()) {
case UP: rect.setY(rect.getY() - 10); break;
case DOWN: rect.setY(rect.getY() + 10); break;
case LEFT: rect.setX(rect.getX() - 10); break;
case RIGHT: rect.setX(rect.getX() + 10); break;
}
});
root.getChildren().add(rect);
Scene scene = new Scene(root, 800, 600);
scene.setOnKeyPressed(event -> rect.requestFocus()); // Focus on rectangle
primaryStage.setTitle("Simple JavaFX Game");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Main
class and select “Run”. A window will appear with a blue rectangle that moves when you press arrow keys.AnimationTimer
(JavaFX) or LWJGL’s glfwSwapBuffers
for smooth animations.By following these steps, you’ll have a fully functional Java game development setup on Ubuntu. Start small, experiment with libraries, and gradually build more complex projects. Happy coding!