Below is a complete step-by-step guide to install Git, Java (JDK), and Maven on Ubuntu and verify that everything is working.
1. Update Ubuntu
Open Terminal:
sudo apt update
sudo apt upgrade -y
2. Install Git
sudo apt install git -y
Verify:
git --version
You should see something similar to:
git version 2.x.x
Configure Git:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
Check configuration:
git config --global --list
3. Install Java JDK
For modern Java development, install OpenJDK:
sudo apt install openjdk-21-jdk -y
Verify Java:
java -version
Also verify the compiler:
javac -version
You should see something like:
openjdk version "21.x.x"
javac 21.x.x
Check where Java is installed:
which java
and:
readlink -f $(which java)
4. Set JAVA_HOME
Find the Java installation:
dirname $(dirname $(readlink -f $(which java)))
For example:
/usr/lib/jvm/java-21-openjdk-amd64
Add JAVA_HOME to your shell configuration:
nano ~/.bashrc
Add at the bottom:
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
Save with:
Ctrl + O → Enter → Ctrl + X
Then reload:
source ~/.bashrc
Verify:
echo $JAVA_HOME
You should get:
/usr/lib/jvm/java-21-openjdk-amd64
5. Install Maven
sudo apt install maven -y
Verify:
mvn -version
You should see something similar to:
Apache Maven 3.x.x
Maven home: /usr/share/maven
Java version: 21.x.x
Java home: /usr/lib/jvm/java-21-openjdk-amd64
The important part is that Maven reports the Java version and Java home correctly.
6. Verify the complete setup
Run:
git --version
java -version
javac -version
mvn -version
Your Ubuntu development environment is now ready:
Git
↓
Java JDK
↓
Maven
↓
Java Project
7. Test Maven with a Java project
Create a project:
mkdir ~/java-project
cd ~/java-project
Generate a Maven project:
mvn archetype:generate \
-DgroupId=com.example \
-DartifactId=hello-world \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.5 \
-DinteractiveMode=false
Enter the project:
cd hello-world
Build it:
mvn clean package
If successful, you’ll see:
BUILD SUCCESS
Run the generated Java program:
java -cp target/hello-world-1.0-SNAPSHOT.jar com.example.App
You should get:
Hello World!
8. Optional: initialize Git
Inside your project:
git init
Check status:
git status
Create the first commit:
git add .
git commit -m "Initial commit"
At this point you have a complete Git + Java + Maven development environment on Ubuntu.