以多个版本JDK的配置,说明update-alternatives的用法
来源:互联网 发布:软件测试零基础 编辑:程序博客网 时间:2024/06/06 10:06
【原文地址】http://maciek.hubpages.com/hub/Ubuntu-Install-Sun-Java-Alternatives
There are variety of ways you can have Java (JDK) installed on your Ubuntu. You can stick with the defaultOpenJDK (openjdk-6-jdk package in Ubuntu repository) or install Sun (it’sOracle now actually) Java (sun-java6-jdk package) from Ubuntu’s multiverse repository using package manager (apt-get). Usually they are couple of revisions behind official Sun JDKreleases, but most of the time it is enough.
Sometimes however you want to (or need to) install the latest version of Java. Downloading and unpacking it is quite easy. However making it the default Java installation in your system is harder. You can of course manually change all or part of the symbolic links pointing to java commands, but it just doesn’t feel like the proper way to do it. Why not use theupdate-java-alternatives command that makes changes system-wide and allows to easily change the default distribution at any time.
Unfortunately update-java-alternatives knows nothing about your manually downloaded JDK, so below are steps that adds new alternative to the registry ofJDKs available.
Notice that all the commands presented here should be pasted as one line in your terminal (even if they are split by browser).
Install Java step by step
- Download JDK from Sun/Oracle. Choose bin version (not rpm). The file would be in form of jdk-version-platform.bin (in my case it was: jdk-6u25-linux-x64.bin )
- Add execution rights to the downloaded file
$ chmod u+x jdk-6u25-linux-x64.bin - Execute script. It will unpack its content to current directory (press Enter when asked)
$ ./jdk-6u25-linux-x64.bin
Now you should have directory i.e. jdk1.6.0_25/ with JDK files in it. - Move unpacked JDK to final destination e.g. /opt/java/
$ sudo mv jdk1.6.0_25/ /opt/java/ - Create symbolic link to that directory that will represent this JDK in general regardless current version. It will ease the future updates of JDK. I can any name. I have chosen sun-java6-manual
$ cd /opt/java/
$ sudo ln -s jdk1.6.0_25 sun-java6-manual - Now create another symbolic link in /usr/lib/jvm pointing to previous one.
$ cd /usr/lib/jvm/
$ sudo ln -s /opt/java/sun-java6-manual - I assume that you have already installed Sun JDK from Ubuntu repositories before. If this is the case then there should be .java-6-sun.jinfo file in /usr/lib/jvm/directory. We will copy that file and modify it. If there is no such file you can download it to current directory with this command:
$ sudo apt-get -d install sun-java6-bin && find /var/cache/apt/archives/ -iname sun-java6-bin* -exec ar -p '{}' data.tar.gz \; | tar -zxO ./usr/lib/jvm/.java-6-sun.jinfo | sudo tee .java-6-sun.jinfo
You can delete it afterwards. The reason I am not using .java-6-openjdk.jinfo file that probably is present in your Ubuntu installation is that it is slightly different that Sun’s one (some browser plugin entries are missing).
Copy file and replace path entries that they point to created link in /usr/lib/jvm/
$ sudo sed s/java-6-sun/sun-java6-manual/ .java-6-sun.jinfo | sudo tee .sun-java6-manual.jinfo - Now edit the beginning of file so it looks like below:
$ sudo vim .sun-java6-manual.jinfo
name=sun-java6-manual
alias=sun-java6-manual
priority=30
Choose whatever priority you like. - Now we have to register new alternatives in update-alternatives mechanism.
$ cat .sun-java6-manual.jinfo | grep -E '^(jre|jdk)' | awk '{print "/usr/bin/" $2 " " $2 " " $3 " 30 \n"}' | xargs -t -n4 sudo update-alternatives --verbose --install - Do the same with plugins
$ sudo update-alternatives --verbose --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /usr/lib/jvm/sun-java6-manual/jre/lib/amd64/libnpjp2.so 30
$ sudo update-alternatives --verbose --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /usr/lib/jvm/sun-java6-manual/jre/lib/amd64/libnpjp2.so 30 - Now we are ready to switch default Java to the new one.
$ update-java-alternatives -l
It should list available java alternatives. It may look like:
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun
sun-java6-manual 1500 /usr/lib/jvm/sun-java6-manual - Set chosen option with:
$ sudo update-java-alternatives -s sun-java6-manual - Now confirm that java command is the new installed one
$ java -version
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)
Updating JDK
When you want to update JDK, download and unpack somewhere and change link/opt/java/sun-java6-manual to point to it.
- 以多个版本JDK的配置,说明update-alternatives的用法
- update-alternatives的说明
- update-alternatives的说明
- Linux:多个 jdk 的安装和管理 update-alternatives , 或 alternatives
- Linux中使用update-alternatives配置多个jdk
- Linux中使用update-alternatives配置多个jdk
- Ubuntu 安装多版本JDK --使用update-alternatives 管理多个版本
- Linux下多版本jdk的切换 alternatives
- update-alternatives命令说明简介及用法
- Ubuntu 中采用 update-alternatives 配置软件多版本
- 安装多个版本的JDK配置
- 【Linux】使用update-alternatives命令进行版本的切换
- 【Linux】使用update-alternatives命令进行版本的切换
- [Ubuntu]update-alternatives命令说明简介及用法
- jdk配置,修改文件方式和update-alternatives命令方式
- 用update-alternatives实现不同Android平台编译时的JDK选择
- dataadapter 的Update 用法说明
- linux下使用update-alternatives切换java版本的正确姿势
- 黑马程序员_java语言基础
- Jsoup简介——使用Java抓取网页数据
- 如何用虚拟机安装linux系统
- 微软等数据结构+算法面试100题全部答案集锦
- 在编译 squashfs4.2时候fatal error: zlib.h & lzma.h : No such file or directory
- 以多个版本JDK的配置,说明update-alternatives的用法
- 走近腾讯 走进腾讯
- hdu 1041 Computer Transformation(大数递推)
- Git 基础 - 撤消操作
- 关于后飞的笨鸟儿
- html select标签操作
- Ubuntu搭建Ftp服务器【图文解说 包成功!】
- 第八周项目三—多分段求值
- Unity Prefabs