標籤:style blog http color io os 使用 ar java
系統內容為:ubuntu 14.04
一、JDK 自動安裝指令碼
jdk自動安裝bash shell指令碼,截止今天(2014/10/15)親測可用:
sudo su #切換到root許可權mkdir /usr/local/javacd /usr/local/java#download jdk 1.7.67wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.tar.gz#extract jdktar -xvf jdk-7u67-linux-x64.tar.gz#set environmentexport JAVA_HOME="/usr/local/java/jdk1.7.0_67"if ! grep "JAVA_HOME=/usr/local/java/jdk1.7.0_67" /etc/environment then echo "JAVA_HOME=/usr/local/java/jdk1.7.0_67" | sudo tee -a /etc/environment echo "export JAVA_HOME" | sudo tee -a /etc/environment echo "PATH=$PATH:$JAVA_HOME/bin" | sudo tee -a /etc/environment echo "export PATH" | sudo tee -a /etc/environment echo "CLASSPATH=.:$JAVA_HOME/lib" | sudo tee -a /etc/environment echo "export CLASSPATH" | sudo tee -a /etc/environment fi#update environmentsource /etc/environment ehco "jdk is installed !"
簡單解釋一下:用wget直接下載jdk和tar.gz包,然後解壓,然後再修改系統內容變數,並更新。
輸入javac 或java -version即可進行驗證。
JAVA_HOME=/usr/jdk1.7.0_67
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
CLASSPATH=.:$JAVA_HOME/lib
export CLASSPATH
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME=/usr/local/java/jdk1.7.0_67
二、Tomcat 自動安裝指令碼
#install tomcatsduo sumkdir /usr/local/tomcatcd /usr/local/tomcatwget http://apache.fayea.com/apache-mirror/tomcat/tomcat-7/v7.0.56/bin/apache-tomcat-7.0.56.tar.gztar -xvf apache-tomcat-7.0.56.tar.gz#change port 8080 to 80sed -i ‘s/8080/80/‘ apache-tomcat-7.0.56/conf/server.xml#startupnohup ./apache-tomcat-7.0.56/bin/startup.sh
註:同樣是使用wget進行下載Tomcat tar.gz包,然後解壓,解壓完成以後使用sed命令更改預設連接埠號碼8080為80,然後使用nohup命令進行後台服務啟動!
附windows環境下安裝jdk配置:
jdk官方:http://www.oracle.com/technetwork/java/javase/downloads/index.html
windows:1)在系統變數裡建立JAVA_HOME變數,變數值為:C:\Java\jdk1.7.0_67(根據自己的安裝路徑填寫)2)建立classpath變數,變數值為:.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar3)在path變數(已存在不用建立)添加變數值:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin(注意變數值之間用“;”隔開)
參考:
1、how-to-automate-download-and-installation-of-java-jdk-on-linux
2、linux shell 指令碼攻略學習19--sed命令詳解
實用指令碼----Linux下Jdk和Tomcat自動安裝shell指令碼總結