1.下载jdk-6u20-linux-i586.bin
2.放到/usr/java目录下
3.#chmod +x jdk-6u20-linux-i586.bin增加执行权限
4.#./jdk-6u20-linux-i586.bin执行该文件
5./etc/profile中增加下面内容
export JAVA_HOME=/usr/java/jdk1.6.0_20
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
6.#source /etc/profile使该文件生效
7.此时java安装成功,通过#java -version 查看java版本
8.如果linux环境上之前已经安装过其他版本的java,通过9、10切换刚刚安装成功的java
9.执行下面命令,将自己安装的java设置为默认java版本
sudo update-alternatives –install /usr/bin/java java /usr/java/jdk1.6.0_20/bin/java 300
sudo update-alternatives –install /usr/bin/javac javac /usr/java/jdk1.6.0_20/bin/javac 300
sudo update-alternatives –install /usr/bin/jar jar /usr/java/jdk1.6.0_20/bin/jar 300
sudo update-alternatives –install /usr/bin/javah javah /usr/java/jdk1.6.0_20/bin/javah 300
sudo update-alternatives –install /usr/bin/javap javap /usr/java/jdk1.6.0_20/bin/javap 300
10.执行下面命令,选择自己安装的java版本
sudo update-alternatives –config java
安装成功后发现下载的eclipse需要最低jdk版本1.7,在redhat4上转jdk1.6,执行java -version 时报错:
[root@localhost root]# javac -version
Error: dl failure on line 864
Error: failed /usr/java/jdk1.7.0_17/jre/lib/i386/client/libjvm.so, because /lib/tls/libc.so.6: version `GLIBC_2.4′ not found (required by /usr/java/jdk1.7.0_17/jre/lib/i386/client/libjvm.so)
网上查是因为redhat版本太低,安装jdk1.7,需要redhat5.5。参考:https://forums.oracle.com/forums/thread.jspa?messageID=10751275
redhat5.5上安装jdk1.7:
1.下载jdk-7u7-linux-i586.tar.gz。
2.放到/usr/java目录下,tar xzvf jdk-7u7-linux-i586.tar.gz
3.参照安装jdk1.6设置环境变量及将自己安装的java设置为默认java.
4.执行java -version 报错:
Error: dl failure on line 864
Error: failed /usr/java/jdk1.7.0_07/jre/lib/i386/client/libjvm.so, because /usr/java/jdk1.7.0_07/jre/lib/i386/client/libjvm.so: cannot restore segment prot after reloc: Permission denied
网上查需要把selinux关掉:
1。打开/etc/selinux/config
2。把selinux=enforcing改为selinux=disabled
3。重启linux