Created
June 9, 2018 23:38
-
-
Save goldfish07/891998fd8ad7ed24f8d985f7b3eb9b51 to your computer and use it in GitHub Desktop.
How to install maven onn latest Ubuntu 18.04 bionic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###########Installing Apache maven on Ubuntu 18.04###################### | |
Note :- do this installtion process as SuperUser | |
Step 1 -Install Java on Ubuntu 18.04 | |
In this tutorial, we will be using the Java packages from the PPA repository, so we need to add the Java PPA Repository to the system. | |
Before adding a new repository, install the 'software-properties-common' package using the apt command below. | |
_______________________________________________________________________ | |
sudo apt install software-properties-common apt-transport-https -y | | |
----------------------------------------------------------------------- | |
Now add the 'webupd8team' PPA repository to the server. | |
sudo add-apt-repository ppa:webupd8team/java -y | |
Note: | |
On Ubuntu 18.04, the 'add-apt-repository' command will automatically update the repository. | |
Apache Maven requires the JDK 1.7 or above. And for this guide, we will install the JDK 1.8. | |
The 'webupd8team' repository has been added to the server, install the Java 8 installer from the PPA repository using the apt command below. | |
sudo apt install oracle-java8-installer -y | |
During the installation, you will be prompted about the Oracle Binary License. Choose 'OK'. | |
Accept the Oracle License by choosing the 'YES' button. | |
When the installation is complete, check the java version. | |
java -version | |
You will see a result similar to the following. | |
Java has been installed on the Ubuntu 18.04 server. | |
Step 2 - Download Apache Maven | |
In this step, we will download the apache maven binary code using the wget command. And we will be using the '/opt/apache-maven' directory as the Maven home directory. | |
Go to the '/opt' directory and download the Apache Maven Binary code. | |
cd /opt/ | |
wget http://www-eu.apache.org/dist/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz | |
Extract the maven.tar.gz file, then rename the maven directory to 'apache-maven'. | |
tar -xf apache-maven-3.5.3-bin.tar.gz | |
mv apache-maven-3.5.3/ apache-maven/ | |
Now you get the 'apache-maven' directory that contains apache maven binary files and other. | |
Step 3 - Configure Apache Maven Environment | |
In this step, we will configure the environment for Apache Maven. We will define some environment variables that are needed by Apache Maven, including 'JAVA_HOME', M2_HOME, and the PATH environment for the maven binary files. | |
Go to the '/etc/profile.d' directory and create a new configuration file 'maven.sh'. | |
cd /etc/profile.d/ | |
vim maven.sh | |
Paste the following configuration below. | |
# Apache Maven Environment Variables | |
# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2 | |
export JAVA_HOME=/usr/lib/jvm/java-8-oracle | |
export M2_HOME=/opt/apache-maven | |
export MAVEN_HOME=/opt/apache-maven | |
export PATH=${M2_HOME}/bin:${PATH} | |
Save the changes and exit. | |
Now make the 'maven.sh' script executable and then apply the configuration by running the 'source' command. | |
chmod +x maven.sh | |
source maven.sh | |
The Apache Maven environment setup has been completed. | |
Now to use maven as normal user not as Superuser | |
add export PATH=/opt/apache-maven/bin:$PATH to .bash.rc in home folder | |
Step 4 - Testing Maven | |
To verify the maven installation, we can run the following maven command. | |
mvn --version | |
mvn --help | |
And you should get the result as shown below. | |
Apache Maven 3.5 installation has been completed. It's running under Linux 64-bit, with Java 1.8 installed, and the Maven home directory is '/opt/apache-maven'. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment