ubuntu(Eclipse+JDK) 自动安装脚本

时间:2021-09-05 16:14:34

sudo rm -rf jdk1.8.0_40
sudo rm -rf /usr/lib/jvm

sudo tar -zxvf jdk-8u40-linux-i586.tar.gz
sudo mkdir /usr/lib/jvm
sudo cp -rf jdk1.8.0_40 /usr/lib/jvm/jdk1.8.0_40/

#set

INFO=$(grep "JAVA_HOME=" ~/.profile)
if [ ! -z "$INFO" ] ;
then
    sed  -i -e '/JAVA_HOME=/d' ~/.profile   #删除只用这行就可以了
    sed -i '/CLASSPATH=/i\export JAVA_HOME=/usr/java/jdk1.8.0_40' ~/.profile
else

sudo echo "export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_40" >> ~/.profile

fi

source ~/.profile

INFO=$(grep "JAVA_HOME=" /etc/profile)
if [ ! -z "$INFO" ] ;
then
    sed  -i -e '/JAVA_HOME=/d' /etc/profile   #删除只用这行就可以了
    sed -i '/CLASSPATH=/i\export JAVA_HOME=/usr/java/jdk1.8.0_40' /etc/profile
else

sudo echo "# JDK config" >> /etc/profile

sudo echo "export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_40" >> /etc/profile
sudo echo "export JRE_HOME=/usr/lib/jvm/jdk1.8.0_40/jre" >> /etc/profile
sudo echo 'export CLASSPATH=".:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH"' >> /etc/profile
sudo echo 'export PATH="$JAVA_HOME/bin:$JRE_HOME/bin:$PATH"' >> /etc/profile

fi

source /etc/profile

java -version

sudo rm -rf eclipse
sudo rm -rf /usr/local/eclipse/
sudo rm -rf /usr/share/applications/eclipse.desktop
sudo rm -rf /home/seanxiao/桌面/eclipse.desktop

sudo tar -zxvf eclipse-jee-luna-SR2-linux-gtk.tar.gz
sudo cp -r eclipse /usr/local/eclipse/

sudo touch /usr/share/applications/eclipse.desktop
sudo chmod 777 /usr/share/applications/eclipse.desktop

sudo echo "[Desktop Entry]" >> /usr/share/applications/eclipse.desktop
sudo echo "Encoding=UTF-8" >> /usr/share/applications/eclipse.desktop
sudo echo "Name=eclipse" >> /usr/share/applications/eclipse.desktop
sudo echo "Comment=Eclipse IDE" >> /usr/share/applications/eclipse.desktop
sudo echo "Exec=/usr/local/eclipse/eclipse" >> /usr/share/applications/eclipse.desktop
sudo echo "Icon=/usr/local/eclipse/icon.xpm" >> /usr/share/applications/eclipse.desktop
sudo echo "Terminal=false" >> /usr/share/applications/eclipse.desktop
sudo echo "StartupNotify=true" >> /usr/share/applications/eclipse.desktop
sudo echo "Type=Application" >> /usr/share/applications/eclipse.desktop
sudo echo "Categories=Application;Development;" >> /usr/share/applications/eclipse.desktop

sudo cp /usr/share/applications/eclipse.desktop /home/seanxiao/桌面

sudo chmod 777 /home/seanxiao/桌面/eclipse.desktop

# 清理
sudo rm -rf jdk1.8.0_40
sudo rm -rf eclipse

本文使用软件版本和下载地址:
eclipse:http://mirror.hust.edu.cn/eclipse//technology/epp/downloads/release/luna/SR2/eclipse-jee-luna-SR2-linux-gtk.tar.gz
jdk:http://download.oracle.com/otn-pub/java/jdk/8u40-b25/jdk-8u40-linux-i586.tar.gz