java和tomcat環境配置已經有不少教程和文章,最近項目須要配置Ubuntu 16.04.2下的古老的java6和tomcat 6,遇到小坑,特記錄和分享。html
網上的教程不是太新,就是太老,還有一些是抄來抄去錯誤百出。本文呈現的是較新的操做系統版本下的老舊開發環境,而且全部腳本都是系統真實運行的拷貝,不是截屏,徹底能夠拷貝運行。java
肯定安裝環境,Ubuntu 16.04.2 LTS,64bit,Server,沒有圖形界面,在mac上,經過ssh鏈接linux
1 $ uname -a 2 Linux s2 4.4.0-83-generic #106-Ubuntu SMP Mon Jun 26 17:54:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/issue Ubuntu 16.04.2 LTS \n \l
sudo add-apt-repository ppa:ferramroberto/Java sudo apt-get update sudo apt-get install sun-java6-jdk sun-java6-plugin
$ sudo apt-get install -y oracle-java6-installer
1.2 推薦路徑shell
Linux x64 | 68.75 MB | jdk-6u45-linux-x64.bin |
$ scp jdk-6u45-linux-x64.bin yourname@yourserver.com:/home/yourname yourname@yourserver.com's password: jdk-6u45-linux-x64.bin 100% 69MB 2.7MB/s 00:25
$ cd /usr/local/java
$ sudo mv ~/jdk-6u45-linux-x64.bin ./
$ chmod +x jdk-6u45-linux-x64.bin $ ls -l total 70404 -rwxr-xr-x 1 yourname yourname 72087592 Jul 27 00:34 jdk-6u45-linux-x64.bin
$ ./jdk-6u45-linux-x64.bin Unpacking... ./jdk-6u45-linux-x64.bin: 44: ./jdk-6u45-linux-x64.bin: cannot create install.sfx.18645: Permission denied Checksumming... /usr/bin/sum: install.sfx.18645: No such file or directory ./jdk-6u45-linux-x64.bin: 62: [: -ne: unexpected operator ./jdk-6u45-linux-x64.bin: 62: [: -ne: unexpected operator chmod: cannot access 'install.sfx.18645': No such file or directory Extracting... ./jdk-6u45-linux-x64.bin: 74: ./jdk-6u45-linux-x64.bin: ./install.sfx.18645: not found Failed to extract the files. Please refer to the Troubleshooting section of the Installation Instructions on the download page for more information.
開始正式安裝tomcat
$ sudo ./jdk-6u45-linux-x64.bin Unpacking... Checksumming... Extracting... ... Creating jdk1.6.0_45/jre/lib/rt.jar Creating jdk1.6.0_45/jre/lib/jsse.jar Creating jdk1.6.0_45/jre/lib/charsets.jar Creating jdk1.6.0_45/lib/tools.jar Creating jdk1.6.0_45/jre/lib/ext/localedata.jar Creating jdk1.6.0_45/jre/lib/plugin.jar Creating jdk1.6.0_45/jre/lib/javaws.jar Creating jdk1.6.0_45/jre/lib/deploy.jar Done.
$ sudo vi /etc/profile
原有內容後面附加以下內容
//原有內容後面附加
export JAVA_HOME=/usr/local/jdk/jdk1.6.0_45
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin
$ source /etc/profile
方式2:安全
$ vi .bashrc
原有內容後面附加
//原有內容後面附加 export JAVA_HOME=/usr/local/jdk/jdk1.6.0_45 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin
$ java -version java version "1.6.0_45" Java(TM) SE Runtime Environment (build 1.6.0_45-b06) Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
若是沒有成功,則可能出現以下信息:bash
$ java -version The program 'java' can be found in the following packages: * default-jre * gcj-5-jre-headless * openjdk-8-jre-headless * gcj-4.8-jre-headless * gcj-4.9-jre-headless * openjdk-9-jre-headless Try: sudo apt install <selected package>