如果,系统中没有安装jdk,详见《1.安装jdk》进行相关jdk的安装配置。

【软件版本说明】

软件名 版本号
jdk 1.8.121
maven 3.5

1.一键安装jdk脚本

  1. #!/bin/bash
  2. #this shell to use installing maven3.5
  3. echo "this shell to use installing and maven3.5"
  4. echo "------------------start to install jdk----------------------"
  5. #sudo su #切换到root权限
  6. echo "------------------------------------------------------------"
  7. echo "------------------start to install maven--------------------"
  8. mkdir /usr/local/maven3
  9. cd /usr/local/maven3
  10. #download maven 3.5.0
  11. wget https://coding.net/u/jamesz2011/p/ubuntu_lib/git/raw/master/jdk/apache-maven-3.5.0-bin.tar.gz
  12. #extract maven
  13. tar -xvf apache-maven-3.5.0-bin.tar.gz -C /usr/local/maven3
  14. #set environment
  15. export M2_HOME="/usr/local/maven3/apache-maven-3.5.0"
  16. if ! grep M2_HOME="/usr/local/maven3/apache-maven-3.5.0" /etc/profile
  17. then
  18. echo "M2_HOME=/usr/local/maven3/apache-maven-3.5.0" | sudo tee -a /etc/profile
  19. echo "export M2_HOME" | sudo tee -a /etc/profile
  20. echo "PATH=${M2_HOME}/bin:$PATH" | sudo tee -a /etc/profile
  21. echo "export PATH" | sudo tee -a /etc/profile
  22. fi
  23. #update profile
  24. #su jamesz2011
  25. source /etc/profile
  26. echo "------------------end to install maven----------------------"
  27. sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_121/bin/java 300
  28. sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_121/bin/javac 300
  29. sudo update-alternatives --install /usr/bin/mvn mvn /usr/local/maven3/apache-maven-3.5.0/bin/mvn 400
  30. sudo update-alternatives --config java
  31. sudo update-alternatives --config javac
  32. echo "------------------------------------------------------------"
  33. echo "------------------install jdk_maven is over-----------------"

2.install_maven.sh文件地址:

3.用法:

  1. wget https://coding.net/u/jamesz2011/p/ubuntu_lib/git/raw/master/jdk/install_maven.sh
  2. sudo chmod a+x/install_maven.sh
  3. sudo source/install_maven.sh

4.验证是否安装成功:

输入 mvn -versoin [若出现版本号,则安装成功]