1. 下载jdk略.
2. 将jdk相关文件目录放到指定目录
(1) 创建jdk目录 /usr/java/jdk7
mkdir -p /usr/java/jdk7
(2) 解压缩jdk压缩包,并移动至指定目录
tar vxf jdk1.7.0_25.tar.gz
mv jdk1.7.0_25 /usr/java/jdk7
3. 配置环境变量
vi ~/.bashrc
#在文件的末尾添加以下内容
export JAVA_HOME=/usr/java/jdk7
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
#刷新~/.bashrc
source ~/.bashrc
注意:=两边不能有空格!
4. 配置系统默认的JDK
由于一些Linux的发行版中已经存在默认的JDK,如OpenJDK等。所以为了使得我们刚才安装好的JDK版本能成为默认的JDK版本,我们还要进行下面的配置。
执行下面的命令:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk7/bin/java
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk7/bin/javac #查看当前jdk
sudo update-alternatives --config java
5. 遇到的一个问题:
执行 java命令报错如下:
Error: failed /usr/java/jdk7/jre/lib/i386/client/libjvm.so,
because /usr/java/jdk7/jre/lib/i386/client/libjvm.so: cannot restore segment prot after reloc: Permission denied
经查询这是selinux(security enhance linux)导致的权限问题,需要对其进行以下调整
(1)编辑/etc/selinux/config,找到这段:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
把 SELINUX=enforcing 注释掉:#SELINUX=enforcing ,然后新加一行为:
SELINUX=disabled
保存,关闭。
(2) 对错误中提到的/usr/java/jdk7/jre/lib/i386/client/libjvm.so进行单独设置:
chcon -t texrel_shlib_t /usr/java/jdk7/jre/lib/i386/client/libjvm.so
问题解决!