如果,系统中没有安装jdk,详见《1.安装jdk》进行相关jdk的安装配置。
【软件版本说明】
软件名 | 版本号 |
---|---|
jdk | 1.8.121 |
maven | 3.5 |
1.一键安装jdk脚本
#!/bin/bash
#this shell to use installing maven3.5
echo "this shell to use installing and maven3.5"
echo "------------------start to install jdk----------------------"
#sudo su #切换到root权限
echo "------------------------------------------------------------"
echo "------------------start to install maven--------------------"
mkdir /usr/local/maven3
cd /usr/local/maven3
#download maven 3.5.0
wget https://coding.net/u/jamesz2011/p/ubuntu_lib/git/raw/master/jdk/apache-maven-3.5.0-bin.tar.gz
#extract maven
tar -xvf apache-maven-3.5.0-bin.tar.gz -C /usr/local/maven3
#set environment
export M2_HOME="/usr/local/maven3/apache-maven-3.5.0"
if ! grep M2_HOME="/usr/local/maven3/apache-maven-3.5.0" /etc/profile
then
echo "M2_HOME=/usr/local/maven3/apache-maven-3.5.0" | sudo tee -a /etc/profile
echo "export M2_HOME" | sudo tee -a /etc/profile
echo "PATH=${M2_HOME}/bin:$PATH" | sudo tee -a /etc/profile
echo "export PATH" | sudo tee -a /etc/profile
fi
#update profile
#su jamesz2011
source /etc/profile
echo "------------------end to install maven----------------------"
sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_121/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_121/bin/javac 300
sudo update-alternatives --install /usr/bin/mvn mvn /usr/local/maven3/apache-maven-3.5.0/bin/mvn 400
sudo update-alternatives --config java
sudo update-alternatives --config javac
echo "------------------------------------------------------------"
echo "------------------install jdk_maven is over-----------------"
2.install_maven.sh文件地址:
3.用法:
wget https://coding.net/u/jamesz2011/p/ubuntu_lib/git/raw/master/jdk/install_maven.sh
sudo chmod a+x/install_maven.sh
sudo source/install_maven.sh
4.验证是否安装成功:
输入 mvn -versoin [若出现版本号,则安装成功]