Agentic AI with Java: Live Cohort
MavenInstalling Maven

Maven Installation on Cloud Linux VM

Launch an Amazon Linux EC2 instance, connect over SSH, install Maven and Java with one dnf command, verify the versions, and clean up the instance after practice.

If you would rather not install anything on your laptop, a small Linux server in the cloud is a great place to practise Maven. It also matches reality: in most companies Maven runs on Linux build servers and CI agents, not on Windows desktops. This lesson is optional. If you already installed Maven locally, you can skip it.

Step 1: launch the EC2 instance

Log in to the AWS console, search for EC2, and click Launch instance. Fill in the form like this:

SettingValue used in the demoWhy
Namemaven-serverAny name you like. It only helps you find the instance
AMI (OS image)Amazon Linux 2023Free, maintained by AWS, uses dnf/yum
Instance typeA free tier eligible type (t2.micro or t3.micro, the console marks it)Enough for small Maven builds
Key pairCreate new, for example telusko-key-pair, type RSA, format .pemThe private key you use to log in. It downloads once, keep it safe
Network settingsAllow SSH traffic. Prefer My IP over AnywhereOnly you should be able to reach port 22

Click Launch instance, then open Instances. Wait until the state is Running and the status checks pass, usually under a minute.

If this is your first time with EC2, the Linux course has a full walkthrough with screenshots: Launching a Linux VM on AWS.

Large builds and micro instances

A micro instance has 1 GB of memory. That is fine for the projects in this course. A big multi-module project or a Spring Boot build with many tests can run out of memory on it. In that case use a larger type such as t3.medium, and remember it is not free.

Step 2: connect over SSH

Select the instance, click Connect, and open the SSH client tab. AWS shows you the exact commands. From the folder where your .pem file was downloaded, open Git Bash (Windows) or Terminal (macOS/Linux) and run:

# Make the key readable only by you. SSH refuses keys that others can read
chmod 400 telusko-key-pair.pem

# Connect. Replace the host with the Public DNS or public IP shown in the console
ssh -i "telusko-key-pair.pem" ec2-user@ec2-13-233-xx-xx.ap-south-1.compute.amazonaws.com

Type yes the first time to trust the host. Check where you are:

pwd       # /home/ec2-user
whoami    # ec2-user

The detailed version of this step, including common SSH errors, is in Connecting to EC2 Instance Using Git Bash.

Step 3: install Maven (and Java with it)

On Amazon Linux 2023 one command installs both:

sudo dnf install -y maven
PartMeaning
sudoRun as root, because installing software changes system folders
dnfThe package manager on Amazon Linux 2023. yum still works as an alias, which is what the video uses
install mavenInstall the maven package
-yAnswer "yes" to the confirmation prompt automatically

You do not need to install Java separately here. The Maven package depends on Java, so the package manager installs Amazon Corretto (AWS's free OpenJDK build) automatically.

Step 4: verify

mvn -v
java -version
Terminal on Amazon Linux showing mvn -v output with Apache Maven 3.8.4 and Java 17 Amazon Corretto

On the demo VM, the Amazon Linux package installed Maven 3.8.4 running on Java 17 (Amazon Corretto).

Notice the Maven version. The distribution package is behind the official latest release (3.10.0 at the time of writing). That is perfectly fine for this course. Older Maven versions use older default plugin versions, so your build logs may show slightly different plugin numbers than mine. The commands and results are the same.

Step 5: stop or terminate when you are done

A running instance can cost money once you are outside the free tier limits. When you finish a practice session:

ActionWhat happensWhen to use
StopThe VM shuts down. Disk and installed software stay. Start it again later and Maven is still thereYou will continue tomorrow
TerminateThe VM and its disk are deleted permanentlyYou are finished with this setup

In the console: select the instance, then Instance state > Stop instance or Terminate (delete) instance. After a terminate, you would have to reinstall Java and Maven on a new instance.

Public IP changes after stop and start

Without an Elastic IP, the instance gets a new public IP and DNS name every time it starts. Copy the new address from the console before you SSH in again.

Try It Yourself

  1. Launch an Amazon Linux 2023 instance, connect with SSH and install Maven with dnf.
  2. Run mvn -v and write down the Maven version, the Maven home and the Java runtime it shows.
  3. Run which mvn and readlink -f $(which mvn) to see where the package placed Maven.
  4. Stop the instance, start it again, reconnect with the new address and confirm mvn -v still works.

Official references


Written By: Shramik Masti

How is this guide?

Last updated on