Java and Maven Install
Installing Latest Oracle Java and Maven. Optionally, you could use SDKMAN CLI and API for installing, switching, removing Java and/or Maven.
Install Oracle Java
Java SE Development Kit 11 LTS release official download page
Extract / install the rpm archive. e.g.,
sudo rpm -Uvh jdk-11.0.5_linux-x64_bin.rpm
Verify that the installed version is is configured as the default Java
sudo alternatives --config java
Verify and/or select the Java from the rpm
archive. e.g. 4,
There are 4 programs which provide 'java'.
Selection Command
-----------------------------------------------
1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.fc30.x86_64/jre/bin/java)
2 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.4.11-0.fc30.x86_64/bin/java)
3 java-latest-openjdk.x86_64 (/usr/lib/jvm/java-13-openjdk-13.0.0.33-1.rolling.fc30.x86_64/bin/java)
*+ 4 /usr/java/jdk-11.0.5/bin/java
Enter to keep the current selection[+], or type selection number:
Verify again w/ java -version
java -version
java version "11.0.5" 2019-10-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)
Application Environment
Application environment setup using /etc/profile.d/*
When a user logs in, environment variables are set from various places. That includes /etc/profile
(for all users).
Then all the shell script (.sh
) files in the /etc/profile.d
directory.
Then ~/.bash_profile
, then ~/.bashrc
.
Setup Java Environment Variables
Add these to a shell script in /etc/profile.d
. e.g.,
java.sh
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
source the file or logout and back in
source /etc/profile.d/java.sh
verify
echo $JAVA_HOME
echo $PATH
echo $CLASSPATH
Install Maven
Verify the release version you want to install at the Maven Download page. Then you can either download from the page or use wget
from the directory where it will be installed. e.g.,
cd /opt
sudo wget https://www-eu.apache.org/dist/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
sudo tar xzf apache-maven-3.6.2-bin.tar.gz
Symlink maven
sudo ln -s apache-maven-3.6.2 maven
Create shell script in profile.d
sudo nano /etc/profile.d/maven.sh
Add these exports to /etc/profile.d/maven.sh
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
Source the file or logout and back in
source /etc/profile.d/maven.sh
verify
mvn --version
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T11:06:16-04:00)
Maven home: /opt/maven
Java version: 11.0.5, vendor: Oracle Corporation, runtime: /usr/java/jdk-11.0.5
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.3.5-200.fc30.x86_64", arch: "amd64", family: "unix"
Lastly, delete the download archive
sudo rm apache-maven-3.6.2-bin.tar.gz
Maven Settings
The settings.xml
file may live in:
- Maven install,
/opt/maven/conf/settings.xml
- User Home:
${HOME}/.m2/settings.xml
If both files exists, their contents gets merged, with the user settings.xml
being dominant.
To create user-specific settings from scratch, copy the global settings from the Maven installation to your
${HOME}/.m2/