Installing Maven on Ec2 Instance
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.
- 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
AWS Instance Connect
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- In the navigation pane, choose Instances.
- Select the instance and choose Connect.
- Choose EC2 Instance Connect.
- Verify the user name and choose Connect to open a terminal window
- use an SSH Client (such as the terminal in your computer), making use of the Key-pair that we created and downloaded to our local computers in the previous steps. We can use
ssh -i aws_private_key.pem \
- use the AWS cli using the AWS commands such as
aws ec2-instance-connect ssh --instance-id i-1234567890example --private-key-file /path/to/key.pem
- 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
- 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
- Now we can install maven with our package installer. In this case we use Yum
sudo yum install -y apache-maven
- Jenkins, maven and every other java application needs java to be installed. Let us do that
sudo yum install java-1.8.0-devel
- 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.
- 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
Once you type this, you will see a maven trying to build your app.