Home › Java Tutorial › Java installation
Java installation
Full step-by-step installation for Windows, macOS and Linux.
Windows
- Open
adoptium.netand download the latest LTS Temurin JDK (.msi). - Run the installer. On the Custom Setup page choose Set JAVA_HOME variable and Add to PATH.
- Click Install and then Finish.
macOS
- Download the .pkg installer from
adoptium.netand run it. Or runbrew install --cask temurin.
Linux (Ubuntu or Debian)
- Run
sudo apt update. - Run
sudo apt install default-jdk.
Check the installation
- Open a new terminal.
- Run
java -versionand thenjavac -version. Both should print a version.
Run your first program
- Create a file named
Main.javaand paste the code from the editor below. - In the terminal, go to that folder.
- Compile with
javac Main.java. This createsMain.class. - Run it with
java Main.
If something goes wrong
'javac' is not recognized: you installed only the runtime, or the PATH is not set. Install the JDK and reopen the terminal.- Class name errors: a public class must have the same name as its file.
Example code
class Main {
public static void main(String[] args) {
System.out.println("Java is installed");
}
}