发布网友 发布时间:2022-04-07 18:04
共2个回答
懂视网 时间:2022-04-07 22:26
jdk-6u45-linux-x64.bin6.创建软链接
root@ubuntu:/opt# ln -s jdk1.6.0_45/ java
root@ubuntu:/opt# ls
java jdk1.6.0_45
7.修改环境变量配置文件
root@ubuntu:/opt# vim /etc/profile
#set java environment
export JAVA_HOME=/opt/java
export JRE_HOME=/opt/java
export CLASSPATH==.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
8.让配置文件生效
root@ubuntu:/opt# source /etc/profile
9.查看java的版本
root@ubuntu:~# java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu1)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
10.查看新配置的JAVA版本
root@ubuntu:~# /opt/java/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)
11.创建链接
root@ubuntu:~# update-alternatives --install /usr/bin/java java /opt/java/bin/java 300
root@ubuntu:~# update-alternatives --install /usr/bin/javac javac /opt/java/bin/javac 300
update-alternatives: using /opt/java/bin/javac to provide /usr/bin/javac (javac) in auto mode
12.配置系统默认的JAVA环境
root@ubuntu:~# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
1 /opt/java/bin/java 300 manual mode
2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
Press enter to keep the current choice[*], or type selection number: 1
root@ubuntu:~# update-alternatives --config javac
There is only one alternative in link group javac (providing /usr/bin/javac): /opt/java/bin/javac
Nothing to configure.
13.查看是否生效
root@ubuntu:~# 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)
本文出自 “云人生” 博客,请务必保留此出处http://ovcer.blog.51cto.com/1145188/1652637
ubuntu中将java环境由安装版的openjdk替换为Oracle的jdk
标签:jdk
热心网友 时间:2022-04-07 19:34
首先去Oracle官网下载RPM或者tar格式的jdk包
然后相应的安装或者解压tar包
最后修改/etc/profile中的环境变量
JAVA_HOME=/usr/jdk7
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
export PATH
注意在Linux中path路径之间用:分隔,在windows中是用;号来分隔
最后执行 source /etc/profile 刷新配置文件
用命令 Java -version来验证是否是oracle的jdk
这里也可以不在全局变量/etc/profile中修改
可以在用户自己的 ~/.bashrc文件中添加,这个是在启动shell是会自动加载的!