Of course! Using Eclipse for Java development on Linux is a very common and powerful setup. This guide will walk you through the entire process, from installation to running your first "Hello, World!" program.

We'll cover:
- Prerequisites: Ensuring you have Java installed.
- Installation: How to get Eclipse on your Linux system.
- First Launch: Starting Eclipse and setting up your workspace.
- Creating a Project: Building your first Java project.
- Writing Code: Creating and running a simple Java class.
- Tips and Troubleshooting: Helpful advice for common issues.
Prerequisites: Install Java (The JRE or JDK)
Eclipse is itself a Java application. To run it, you need a Java Runtime Environment (JRE). To compile and run your Java code, you need the Java Development Kit (JDK). It's best to install the JDK, as it includes the JRE.
Check if Java is Already Installed
Open your terminal (usually Ctrl+Alt+T) and type:
java -version
- If you see a version number (e.g.,
openjdk version "17.0.8"), you're good to go! You can skip to the next section. - If you see an error like "command not found" or "java: command not found", you need to install Java.
Install Java on Linux
The easiest way to install Java is using your system's package manager.

For Debian / Ubuntu / Mint
# Update your package list sudo apt update # Install the default JDK (OpenJDK 17 is a common and stable choice) sudo apt install default-jdk # Verify the installation java -version javac -version # This confirms the compiler is installed
For Fedora / CentOS / RHEL
# Update your package list sudo dnf update # Install the OpenJDK development kit sudo dnf install java-latest-openjdk-devel # Verify the installation java -version javac -version
For Arch Linux
# Update your package list sudo pacman -Syu # Install the OpenJDK development kit sudo pacman -S jdk-openjdk # Verify the installation java -version javac -version
Installation: Downloading and Installing Eclipse
Eclipse does not have a traditional "installer" like you'd find on Windows. You download a compressed archive, extract it, and run the executable.
-
Download Eclipse: Go to the Eclipse Downloads page.
- Choose the "Eclipse IDE for Enterprise Java and Web Developers". This is a popular choice as it includes tools for web, database, and enterprise development, which are useful for most Java projects.
- Find the download link for your system's architecture (usually
x86_64). - You will download a file named something like
eclipse-platform-2025-09-R-linux-gtk-x86_64.tar.gz.
-
Extract the Archive: Open your terminal and navigate to your
Downloadsfolder (or wherever the file is).# Go to the downloads directory cd ~/Downloads # Extract the downloaded file. This will create an 'eclipse' folder. tar -xvf eclipse-platform-*.tar.gz
-
Move Eclipse to a Convenient Location: It's a good practice to put Eclipse in
/optor your~/optdirectory.
(图片来源网络,侵删)# Move the extracted folder to /opt sudo mv eclipse /opt/
Alternatively, you can move it to your home directory if you don't need
sudoprivileges:# Move to your home directory's opt folder mv eclipse ~/opt/
-
(Optional but Recommended) Create a Desktop Shortcut
This makes it easy to launch Eclipse from your application menu.
Method A: Using the .desktop file (Recommended)
# Create a .desktop file for your user nano ~/.local/share/applications/eclipse.desktop
Paste the following text into the file. Make sure to change the path to the eclipse executable if you installed it somewhere else.
[Desktop Entry] Name=Eclipse Type=Application Exec=/opt/eclipse/eclipse Icon=/opt/eclipse/icon.xpm Comment=Eclipse IDE Terminal=false Categories=Development;IDE;
Save the file and exit (
Ctrl+X, thenY, thenEnter).Method B: Drag and Drop
- Open your file manager.
- Navigate to
/opt/eclipse. - Find the
eclipseexecutable. - Drag it to your desktop or your application list.
First Launch: Starting Eclipse
-
Launch Eclipse from your application menu or by running it from the terminal:
# If you moved it to /opt /opt/eclipse/eclipse # If you moved it to ~/opt ~/opt/eclipse/eclipse
-
Select a Workspace: Eclipse will ask you to choose a "workspace". This is the folder where it will store all your projects' metadata. You can accept the default or create a new folder for your projects (e.g.,
~/workspace). Check the box "Use this as the default and do not ask again" if you don't want to be prompted each time. -
The Eclipse IDE will open. You'll see a welcome screen. You can close it or explore the "What's new" section.
Creating Your First Java Project
- In the top menu, go to File -> New -> Java Project.
- Project Name: Give your project a name, for example,
HelloWorld. - Location: This should default to your workspace folder. You can leave it as is.
- JRE: Ensure the correct JDK version is selected. It should automatically detect the one you installed.
- Click Finish.
Eclipse will create your project and show it in the "Project Explorer" view on the left. You'll see a src (source) folder inside.
Writing and Running Code
-
Create a Package (Good Practice): Right-click on the
srcfolder and go to New -> Package.- Name:
com.example.helloworld - Click Finish. This creates a package structure to organize your code.
- Name:
-
Create a Class: Right-click on the new package (
com.example.helloworld) and go to New -> Class.- Name:
Main - Make sure the box
public static void main(String[] args)is checked. This will create the main method, which is the entry point for your Java application. - Click Finish.
- Name:
-
Write the Code: A new editor tab will open with your
Main.javafile. Replace the placeholder code with this:package com.example.helloworld; public class Main { public static void main(String[] args) { System.out.println("Hello, Eclipse on Linux!"); } } -
Run the Program: There are two easy ways to do this:
- Click the green "Run" button (▶) in the toolbar.
- Right-click anywhere in the editor and select Run As -> Java Application.
-
See the Output: The "Console" view at the bottom of the screen will display the output of your program.
Hello, Eclipse on Linux!
Congratulations! You have successfully set up Eclipse for Java development on Linux and run your first program.
Tips and Troubleshooting
Tip: Install a Build Tool (Maven or Gradle)
For any real project, you'll need a build tool like Maven or Gradle to manage dependencies, compile, package, and run your application.
- Maven: Eclipse has excellent Maven support built-in. You can create a "Maven Project" directly from
File -> New. - Gradle: You can install the "Buildship" Eclipse plugin via Help -> Eclipse Marketplace to get Gradle integration.
Troubleshooting: java.lang.UnsupportedClassVersionError
This error means you are trying to run a class file compiled with a newer version of Java than the JRE you are using to run Eclipse.
-
Solution: Ensure the JRE used to launch Eclipse is the same or newer than the JDK you use for compiling. You can specify the JRE for Eclipse by editing its configuration file. Create a file named
eclipse.iniin the/opt/eclipsedirectory (or wherever you installed Eclipse) and add the following lines, pointing to your JDK'sjre/libdirectory:-vm /usr/lib/jvm/java-17-openjdk-amd64/bin/java
Note: The path
/usr/lib/jvm/java-17-openjdk-amd64/bin/javais an example. Find your JDK's path usingwhich javaorls /usr/lib/jvm/.
Troubleshooting: Eclipse is Slow
Eclipse can be resource-intensive. To improve performance:
- Allocate more Memory: Edit the
eclipse.inifile to increase the heap size. Add or modify these lines:-Xms512m -Xmx2048m-Xmsis the initial heap size, and-Xmxis the maximum. 2048m (2GB) is a good starting point for larger projects. - Use a lighter Window Manager: If you're on a lightweight Linux distro, ensure you're not running a heavy desktop environment that consumes resources.
