简体   繁体   中英

Install maven to any linux system using bash script

有什么可能的方法可以使用 bash 脚本在任何 linux 机器上安装 maven 吗?

According to Mkyong , you can install Maven using sudo:

sudo apt-get install maven

then, run

mvn -version

to check that it installed.

Yes you can install mvn with bash script, example below

mvn_version=${mvn_version:-3.8.5}
url="http://www.mirrorservice.org/sites/ftp.apache.org/maven/maven-3/${mvn_version}/binaries/apache-maven-${mvn_version}-bin.tar.gz"
install_dir="/opt/maven"

mkdir ${install_dir}
curl -fsSL ${url} | tar zx --strip-components=1 -C ${install_dir}
cat << EOF > /etc/profile.d/maven.sh
#!/bin/sh
export MAVEN_HOME=${install_dir}
export M2_HOME=${install_dir}
export M2=${install_dir}/bin
export PATH=${install_dir}/bin:$PATH
EOF
source /etc/profile.d/maven.sh
echo maven installed to ${install_dir}
mvn --version

you need to add source /etc/profile.d/maven.sh to ~/.bash_profile or basrch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM