Installing maven and setting JAVA_HOME on CentOS7.
download binary tar.gz from - https://maven.apache.org/download.cgi
move it to /usr/local/src/
- Run below command to untar the file
# tar -xvzf apache-maven-3.6.3-bin.tar.gz
- Rename the default directory
# mv apache-maven-3.6.3/ apache-mvn/
- Go to /etc/profile.d
# vi maven.sh
#!/bin/bash
# Apache Maven Environment Variables
# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2
export M2_HOME=/usr/local/src//apache-mvn/
export PATH=${M2_HOME}/bin:${PATH}
- change the permission to executable
# chmod +x maven.sh
# source maven.sh
[root@katello ~]# mvn -version
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Ran into this error - I had two versions of JDK installed jdk1.8.0_271-i586 and java-11-openjdk-11.0.9.11-0.el7_9.x86_64
- Simply followed the JAVA_HOME to set to the latest Java version
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
#export JAVA_HOME=/usr/java/jdk1.8.0_271-i586
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.9.11-0.el7_9.x86_64
- This fixed the issue.
[root@katello ~]# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/src/apache-mvn
Java version: 11.0.9, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.9.11-0.el7_9.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1127.19.1.el7.x86_64", arch: "amd64", family: "unix"
[root@katello ~]# date
Tue Dec 8 11:54:27 IST 2020
No comments:
Post a Comment