安装脚本:
#!/bin/bashecho "正在创建/usr/lib/jvm/目录"sudo mkdir /usr/lib/jvm/echo "目录/usr/lib/jvm/创建成功"echo "正在安装JDK和Eclipse"os_version=`uname -a`echo $os_versionarchitecture="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/eclipseelse 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/eclipsefiecho "安装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/environmentmv ~/.bashrc ~/.bashrc.backup.javacat ~/.bashrc.backup.java >> ~/.bashrcecho "PATH=\"$PATH:/usr/lib/jvm/jdk1.7.0_60/bin\"" >> ~/.bashrcecho "JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60" >> ~/.bashrcecho "CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar" >> ~/.bashrcsource ~/.bashrcecho "配置环境成功"# 如果有多个java版本需要进行以下配置(包括openjdk)echo "设置默认jdk"sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_60/bin/java 300sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_60/bin/javac 300sudo update-alternatives --config java# echo "设置默认jdk成功"echo "测试是否安装成功"java -versionecho "安装成功"卸载脚本:
echo "正在删除相关文件"sudo rm -rf /usr/lib/jvm/sudo rm -rf /usr/bin/eclipse/sudo rm -rf ~/Desktop/eclipsewaitecho "删除相关文件成功"echo "恢复配置文件"# sudo rm -f /etc/environment# sudo mv /etc/environment.backup.java /etc/environmentsudo rm /usr/bin/java /usr/bin/javacsudo rm /etc/alternatives/java /etc/alternatives/javacmv ~/.bashrc.backup.java ~/.bashrcecho "恢复配置文件成功"