--------------------------------------------------------------------
author:jiangxin
Email:[email protected]
Blog:http://blog.csdn.net/jiangxinnju
--------------------------------------------------------------------
假设大家必须在Linux环境下使用java开发应用程序,会感觉Linux下JDK和Eclipse等相关软件安装都非常复杂,所以我特意写了一个脚本,这是一个在Linux下自己主动安装/卸载JDK和Eclipse的脚本。实现一键安装卸载,无不论什么额外文件产生。大家能够尝试一下。
文件包等下载地址:
http://pan.baidu.com/s/1sjArVM9
脚本可以自己主动识别系统是32位的还是64位的。并自己主动选择Jdk和Eclipse等版本号。
測试环境:
Linux发行版本号:Ubuntu 14.04
JDK版本号:
jdk-7u60-linux-i586(32位)
jdk-7u60-linux-x64(64位)
Eclipse版本号:
eclipse-java-luna-R-linux-gtk(32位)
eclipse-java-luna-R-linux-gtk-x86_64(64位)
使用时请确保此目录存在下面文件:
├── eclipse-java-luna-R-linux-gtk.tar.gz
├── eclipse-java-luna-R-linux-gtk-x86_64.tar.gz
├── install.sh
├── jdk-7u60-linux-i586.tar.gz
├── jdk-7u60-linux-x64.tar.gz
├── README
└── uninstall.sh
你能够尝试改动该脚本以实现更加适合自己等功能。欢迎大家提出改动意见。
部分Linux系统会自带OpenJava,能够在安装前看看java/javac等命令是否有效。
安装脚本:
#!/bin/bash echo "正在创建/usr/lib/jvm/文件夹" sudo mkdir /usr/lib/jvm/ echo "文件夹/usr/lib/jvm/创建成功" echo "正在安装JDK和Eclipse" os_version=`uname -a` echo $os_version architecture="64" echo "$os_version" | grep -q "$architecture" if [ $? -eq 0 ] then echo "您正在使用64位操作系统。为您选择64位JDK和eclipse" sudo tar -zxvf jdk-7u60-linux-x64.tar.gz -C /usr/lib/jvm/ sudo chown -R jiangxin:jiangxin /usr/lib/jvm/jdk1.7.0_60 sudo tar -zxvf eclipse-java-luna-R-linux-gtk-x86_64.tar.gz -C /usr/bin/ sudo chown -R jiangxin:jiangxin /usr/bin/eclipse sudo ln -s /usr/bin/eclipse/eclipse ~/Desktop/eclipse else echo "您正在使用32位操作系统,为您选择32位JDK和eclipse" sudo tar -zxvf jdk-7u60-linux-i586.tar.gz -C /usr/lib/jvm/ sudo chown -R jiangxin:jiangxin /usr/lib/jvm/jdk1.7.0_60 sudo tar -zxvf eclipse-java-luna-R-linux-gtk.tar.gz -C /usr/bin/ sudo chown -R jiangxin:jiangxin /usr/bin/eclipse sudo ln -s /usr/bin/eclipse/eclipse ~/Desktop/eclipse fi echo "安装JDK和Eclipse成功" echo "配置环境变量" # touch environment # echo "PATH=\"$PATH:/usr/lib/jvm/jdk1.7.0_60/bin\"" >> environment # echo "JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60" >> environment # echo "CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar" >> environment # sudo mv /etc/environment /etc/environment.backup.java # sudo mv environment /etc # source /etc/environment mv ~/.bashrc ~/.bashrc.backup.java cat ~/.bashrc.backup.java >> ~/.bashrc echo "PATH=\"$PATH:/usr/lib/jvm/jdk1.7.0_60/bin\"" >> ~/.bashrc echo "JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60" >> ~/.bashrc echo "CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar" >> ~/.bashrc source ~/.bashrc echo "配置环境成功" # 假设有多个java版本号须要进行下面配置(包含openjdk) echo "设置默认jdk" sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_60/bin/java 300 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_60/bin/javac 300 sudo update-alternatives --config java # echo "设置默认jdk成功" echo "測试是否成功安装" java -version echo "成功安装"
卸载脚本:
echo "正在删除相关文件" sudo rm -rf /usr/lib/jvm/ sudo rm -rf /usr/bin/eclipse/ sudo rm -rf ~/Desktop/eclipse wait echo "删除相关文件成功" echo "恢复配置文件" # sudo rm -f /etc/environment # sudo mv /etc/environment.backup.java /etc/environment sudo rm /usr/bin/java /usr/bin/javac sudo rm /etc/alternatives/java /etc/alternatives/javac mv ~/.bashrc.backup.java ~/.bashrc echo "恢复配置文件成功"