How To Install Maven In Linux-Configure Maven In Linux
How To Install Maven In Linux-Configure Maven In Linux
Apache Maven depends on Java so you must have install java in your linux machine. java is the basic prerequisite to install maven in linux machine so first lets install java in linux. In the following steps i will show you how to install maven in linux step by step.
Install Java In Linux
first update the system with update command.
if your system is ubuntu use sudo apt-get update, if your system is centos/rhel use sudo yum update command. after updating the packages install java with below command.
for ubuntu/debian systems
sudo apt-get update -y
centos/rhel
sudo yum update -y
install jdk with with below command in ubuntu machine
sudo apt install default-jdk -y
if your machine is centos/rhel use below command to install jdk
sudo yum install java-1.8.0-openjdk -y
by default jdk will downloaded into /usr/lib/jvm/
devops@ip-10-0-0-30:~$ ls -la /usr/lib/jvm/ total 16 drwxr-xr-x 3 root root 4096 Apr 28 16:56 . drwxr-xr-x 64 root root 4096 Apr 28 16:56 .. -rw-r--r-- 1 root root 1994 Mar 26 20:57 .java-1.11.0-openjdk-amd64.jinfo lrwxrwxrwx 1 root root 25 Feb 20 16:31 default-java -> java-1.11.0-openjdk-amd64 lrwxrwxrwx 1 root root 21 Mar 26 20:57 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64 drwxr-xr-x 9 root root 4096 Apr 28 16:57 java-11-openjdk-amd64
Configure java in linux
to configure java in linux we have add environment variablesĀ in /etc/environment file
vi /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-11-openjdk-amd64/bin" JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
you can see here at the end of the line i appended /usr/lib/jvm/java-11-openjdk-amd64/binĀ to PATH variable and added JAVA_HOME variable.
in JAVA_HOME variable write path of jdk. In my syetm jdk is located in /usr/lib/jvm/java-11-openjdk-amd64/. So this is the JAVA_HOME path varible value.
in PATH variable add up to jdk bin path , to append a path in PATH varible we use colon(:) and path upto jdk
that's it we have successfully configured java jdk in our linux machine.
above configuration is not same in all machines. so use your values in this file.
install apache maven in linux
Download Maven:
By using wget command we can download maven from official Apache maven website.
to install wget command use
sudo apt-get install wget -y for debian/ubuntu systems
sudo yum install wget -y for centos/rhel systems. after installing wget in your system download maven using wget command.
wget http://mirrors.estointernet.in/apache/maven/maven-3/3.6.0/binaries/apache-maven-3.6.0-bin.tar.gz tar -xzf apache-maven-3.6.0-bin.tar.gz mkdir /opt/maven mv apache-maven-3.6.0 /opt/maven
now we have successfully download and extracted maven in /opt/maven directory
devops@ip-10-0-0-30:~$ ls /opt/maven/ apache-maven-3.6.0
Configure maven in Linux:
to configure maven in linux we have to add environment variables in /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-11-openjdk-amd64/bin:/opt/maven/apache-maven-3.6.0/bin" M2_HOME="/opt/maven/apache-maven-3.6.0" JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
same as java variables add maven variables in this file.
in PATH varible add path upto maven bin like /opt/maven/apache-maven-3.6.0/bin
in M2_HOME varible add path up to the maven directory like /opt/maven/apache-maven-3.6.0
Save the file and then reload it or do logout and login again or reboot the system.
to apply changes immediately in your current shell use bellow comand
source /etc/environment
verify maven version
verfy maven version with mvn -version command. it will show you maven version and path of m2_home.
devops@ip-10-0-0-30:~$ mvn -version Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T18:41:47Z) Maven home: /opt/maven/apache-maven-3.6.0 Java version: 11.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64 Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "4.15.0-1032-aws", arch: "amd64", family: "unix"
that's it we have successfully installed maven in linux and configured maven in linux machine.
- how to install apache maven in linux
- install maven in linux
- configure maven in linux
- maven in linux