Today I will teach you how to install one of the most important tools in Java development. This post is about installing Apache Maven on Ubuntu 18.04
Many times developing an application is not as simple as it seems. This process requires a lot of time and a solid knowledge of computers and processes to obtain a good product.
In this sense, despite being a programming language with years on top, the truth is that even Java is quite popular. This means that there are many libraries available, a lot of information and resources that help bring a project to life. Among them is Apache Maven.
What can you do with Apache Maven on Ubuntu 18.04?
So, according to the Apache Maven site,
Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting, and documentation from a central piece of information.
In other words, Apache Maven helps automate the tasks of starting, compiling and testing software made in Java.
On the other hand, Apache Maven has a pretty good feature is the project dependency management. This means that, if the project requires a Maven library, it will look for it on the Internet and configure it. That is great.
For library management, it is also possible to specify a particular version of a library. The program will take care of the rest and without the user having to intervene. It is only necessary for the developer to define what those dependencies are.
Apache Maven features
Apache Maven knows how to delete .class, compile, generate jar, generate Javadoc and generate web documentation. It does all of this without any extra configuration.
The main features of Apache Maven are the following:
- It is open-source. That is, the code is accessible to everyone.
- Thanks to being made in Java, the program is cross-platform. Therefore the developer can use it in the operating system he prefers.
- It incorporates a dependency management system.
- It standardizes the phases of the development cycle and the life of the software.
- Also, it offers perfect integration with the most known IDE’s such as Netbeans or Eclipse.
Despite all the advantages and possibilities that Apache MAve offers us, it is necessary to say that the application is handled from the terminal. This means that there is no graphical user interface and this can be a problem for many.
All the possibilities of Apache Maven are achieved through a POM file which is where the characteristics of the project are defined. As well as the dependencies used. Anyway, as I mentioned, Apache Maven can be integrated into IDS making it easier to use.
Thanks to the presence of the POM file, it is possible to reuse the construction logic of the project. As well as portability and the integration of new tools. Think that this POM file can be copied to another computer and Maven will recognize it and do the same operations as in the source computer.
Installing Apache Maven on Ubuntu 18.04
Maven is an application made with Java. Therefore it is possible to install it on any operating system that has Java.
This means great advantages in the portability and use of it, but it also makes it necessary to fulfill this requirement before using it.
Preparing the system for installation
Before starting to work with Apache Maven, it is necessary to prepare the system by installing some packages.
First, install the wget
and unzip
packages. With wget
you can download files from the Internet from the terminal. While with unzip
, you can unzip zip files.
So, open a terminal and start the installation:
:~$ sudo apt install wget unzip
Then, once they are correctly installed, it is Java’s turn.
Java can be found in the official Ubuntu repositories. In this case, it is possible to install it thanks to the OpenJDK project. So the chosen version will be the 11th.
:~$ sudo apt install openjdk-11-jre
Finally, check the functionality of Java using the following command:
:~$ java -version
Everything is fine, so far.
Download Apache Maven on Ubuntu 18.04
You have everything you need to start the download of Apache Maven.
We recommend downloading from the system’s temporary folder. So access it.
:~$ cd /tmp/
And using the wget
command, start the download.
:~$ wget -c https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip
When the download is complete, the zip file must be unzipped. It will contain the Maven executable binary.
:~$ unzip apache-maven-3.6.3-bin.zip
The next step is to move the generated folder to another directory. It can be /opt/
:~$ sudo mv apache-maven-3.6.3 /opt/maven
Apache Maven is already on the system, but it must be made available as a command from any location.
This is done by creating a file in the /etc/profile.d/
folder
:~$ sudo nano /etc/profile.d/maven.sh
Within the file, add the following content:
export JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 export M2_HOME=/opt/maven export PATH=${M2_HOME}/bin:${PATH}
After saving the changes, close the file.
The system recognizes the new configuration of the created file, by running this command:
:~$ source /etc/profile.d/maven.sh
And now yes, Apache Maven will be available as a command from any location on the system. Also, any user of the system can execute it without problems.
To check if the Maven command works, try to show the installed version:
:~$ mvn -version
And so it is possible to check that Maven is ready for work.
Conclusion
If you are a developer you know how difficult it is to develop a quality application. So many other developers have created applications to help this process. This is the case with Apache Maven.
With Apache Maven, you can perform many operations within the development cycle of an application, quickly and easily. These operations include the creation of the project’s directory structure or something very important such as dependency management.
So now that you know how to install it in a popular system like Ubuntu 18.04, you just have to take advantage of it to the maximum and create fantastic applications.
So, tell us, are you a developer? have you heard about this tool? Have you used it?