Back to overview

Installing Maven on Ec2 Instance

| 2 min read

If you have ever built any java tools, you would have come across build tools. One of the most used ones is called Maven. Today we will look at the steps to install Maven on our AWS EC2 instance.

Let us get started.

  1. First, logon to our AWS console. Next we will open the EC2 service page and login to our EC2 instance. To do this, we can either
ssh -i aws_private_key.pem \ 
ubuntu@ec2-3-135-209-28.us-east-2.compute.amazonaws.com
aws ec2-instance-connect ssh --instance-id i-1234567890example --private-key-file /path/to/key.pem
  1. To install maven we need to do some reconfiguration. We will use this command to add a repo to our EC2 with a maven package
sudo wget https://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
  1. Next, we need to specify the version that we want to install. Enter the following to determine the version number for the packages that you want to install.
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
  1. Now we can install maven with our package installer. In this case we use Yum
sudo yum install -y apache-maven
  1. Jenkins, maven and every other java application needs java to be installed. Let us do that
sudo yum install java-1.8.0-devel
  1. Now that we have finished the installation, we now will go ahead and configure it. We need to setup Java as our default runtime. Let us do that with this command
sudo /usr/sbin/alternatives --config java

You will be prompted to enter the version, type 8 to choose version 8 of Java.

  1. Java is our runtime now … last step, we will setup Java also as our compiler with the command
sudo /usr/sbin/alternatives --config javac

Now if you want to run maven … type the mvn command

mvn 

Once you type this, you will see a maven trying to build your app.

Yay!!!!!! Great job installing Maven!

maven

Did you like this post? Check out my latest blog posts:

Complete CICD Pipeline Java with Jenkins, Nexus, Sonar and AWS services
27 Jul 2023

From Code to Deployment - A Complete CICD journey for Java Apps using Jenkins, Nexus, Sonarqube, AWS ECR & ECS

  • devops
  • aws
  • cicd
Person typing on a laptop
21 Jul 2023

🏗️How to Make Animated ✨GIFs✨ For Amazon Web Services (AWS) Architectures:🏗️ A Step-by-Step Tutorial🏗️

  • aws
  • powerpoint
  • infra
  • resume
Jenkins 101
28 Jun 2023

Jenkins 101: Getting started with Jenkins

  • jenkins
  • devops
  • cicd