Chinaunix首页 | 论坛 | 博客
  • 博客访问: 29295
  • 博文数量: 22
  • 博客积分: 15
  • 博客等级: 民兵
  • 技术积分: 205
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-11 16:20
文章分类

全部博文(22)

文章存档

2015年(10)

2014年(12)

我的朋友

分类: LINUX

2014-08-20 11:16:52

Introduction

As a lot of articles and programs require to have Java installed, this article will guide you through the process of installing and managing different versions of Java.

Installing default JRE/JDK

This is the recommended and easiest option. This will install OpenJDK 6 on Ubuntu 12.04 and earlier and on 12.10+ it will install OpenJDK 7.

Installing Java with apt-get is easy. First, update the package index:
  1. sudo apt-get update
Then, check if Java is not already installed: 
  1. java -version
If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command below, This will install the Java Runtime Environment (JRE). 
  1. sudo apt-get install default-jre

If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command below, That is everything that is needed to install Java.
  1. sudo apt-get install default-jdk

All other steps are optional and must only be executed when needed. 

Installing OpenJDK 7 (optional)

To install OpenJDK 7, execute the following command below, this will install the Java Runtime Environment (JRE).
  1. sudo apt-get install openjdk-7-jre
If you instead need the Java Development Kit (JDK), execute the following command:
  1. sudo apt-get install openjdk-7-jdk
Installing Oracle JDK (optional)
The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.
You can still install it using apt-get. To install any version, first execute the following commands:
  1. sudo apt-get install python-software-properties
  2. sudo add-apt-repository ppa:webupd8team/java
  3. sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:

Oracle JDK 6

This is an old version but still in use.
  1. sudo apt-get install oracle-java6-installer

Oracle JDK 7

This is the latest stable version.
  1. sudo apt-get install oracle-java7-installer

Oracle JDK 8

This is a developer preview, the general release is scheduled for March 2014. This external article about Java 8 may help you to understand what it's all about.
  1. sudo apt-get install oracle-java8-installer

Managing Java (optional)

When there are multiple Java installations on your Droplet, the Java version to use as default can be chosen. To do this, execute the following command:
It will usually return something like this if you have 2 installations (if you have more, it will of course return more):
  1. root@stb-she-003:~# update-alternatives --config java
  2. There are 3 choices for the alternative java (providing /usr/bin/java).
  3. Selection Path Priority Status
  4. ------------------------------------------------------------
  5. 0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
  6. 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
  7. * 2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
  8. 3 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode

  9. Press enter to keep the current choice[*], or type selection number: 3
    update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode.
You can now choose the number to use as default. This can also be done for the Java compiler (javac):
It is the same selection screen as the previous command and should be used in the same way. This command can be executed for all other commands which have different installations. In Java, this includes but is not limited to: keytool, javadoc and jarsigner.
  1. root@stb-she-003:~# javac -version
  2. javac 1.6.0_26
  3. root@stb-she-003:~#
  4. root@stb-she-003:~# update-alternatives --config javac
  5. There are 2 choices for the alternative javac (providing /usr/bin/javac).
  6. Selection Path Priority Status
  7. ------------------------------------------------------------
  8. 0 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 auto mode
  9. 1 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 manual mode
  10. * 2 /usr/lib/jvm/java-6-sun/bin/javac 63 manual mode
  11. Press enter to keep the current choice[*], or type selection number: 2
If need to use javac, then we need to install openjdk-7-jdk below, then select javac 1.7 below:
  1. root@stb-she-003:~# apt-get install openjdk-7-jdk
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. Suggested packages:
  6. openjdk-7-demo openjdk-7-source visualvm
  7. The following NEW packages will be installed:
  8. openjdk-7-jdk
  9. 0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
  10. Need to get 16.6 MB of archives.
  11. After this operation, 20.7 MB of additional disk space will be used.
  12. Get:1 precise-updates/universe openjdk-7-jdk amd64 7u7-2.3.2a-0ubuntu0.12.04.1 [16.6 MB]
  13. Fetched 16.6 MB in 14s (1,115 kB/s)
  14. Selecting previously unselected package openjdk-7-jdk.
  15. (Reading database ... 252394 files and directories currently installed.)
  16. Unpacking openjdk-7-jdk (from .../openjdk-7-jdk_7u7-2.3.2a-0ubuntu0.12.04.1_amd64.deb) ...
  17. Setting up openjdk-7-jdk (7u7-2.3.2a-0ubuntu0.12.04.1) ...
  18. /usr/lib/jvm/java-6-sun/bin/apt
  19. update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/bin/jcmd to provide /usr/bin/jcmd (jcmd) in auto mode.
  1. root@stb-she-003:~# update-alternatives --config javac
  2. There are 3 choices for the alternative javac (providing /usr/bin/javac).
  3. Selection Path Priority Status
  4. ------------------------------------------------------------
  5. 0 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 auto mode
  6. 1 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 manual mode
  7. * 2 /usr/lib/jvm/java-6-sun/bin/javac 63 manual mode
  8. 3 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac 1051 manual mode
  9. Press enter to keep the current choice[*], or type selection number: 3
  10. update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode.



Setting the "JAVA_HOME" environment variable

To set the JAVA_HOME environment variable, which is needed for some programs, first find out the path of your Java installation:
  1. root@stb-she-003:~# update-alternatives --config java
  2. There are 3 choices for the alternative java (providing /usr/bin/java).
  3. Selection Path Priority Status
  4. ------------------------------------------------------------
  5. 0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode
  6. 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
  7. * 2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
  8. 3 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode
  9. Press enter to keep the current choice[*], or type selection number: 
The path of the installation is for each:
  1. /usr/lib/jvm/java-6-openjdk-amd64
  2. /usr/lib/jvm/java-6-sun/
  3. /usr/lib/jvm/java-7-openjdk-amd64
Copy the path from your preferred installation and then edit the file /etc/environment:
  1. sudo vim /etc/environment
In this file, add the following line (replacing YOUR_PATH by the just copied path):
  1. JAVA_HOME="YOUR_PATH"
That should be enough to set the environment variable. Now reload this file:
  1. source /etc/environment
Test it by executing:
  1. echo $JAVA_HOME
If it returns the just set path, the environment variable has been set successfully. If it doesn't, please make sure you followed all steps correctly.

Specially, on my server do follow:

  1. apt-get update

  2. apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386  libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
  1. apt-get install default-jre default-jdk openjdk-7-jre openjdk-7-jdk

  2. update-alternatives --config java
  3. update-alternatives --config javac

Updated, install JDK8 on Ubuntu 14/12

点击(此处)折叠或打开

  1. 1. add-apt-repository ppa:openjdk-r/ppa
  2. 2. apt-get update
  3. 3. apt-get install openjdk-8-jdk
  4. 4. update-alternatives --config java
  5. 5. java -version
  6. root@bld-bei-016:~# update-alternatives --config java
  7. There are 4 choices for the alternative java (providing /usr/bin/java).
  8. Selection Path Priority Status
  9. ------------------------------------------------------------
  10. 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1069 auto mode
  11. 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
  12. 2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
  13. * 3 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode
  14. 4 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1069 manual mode
  15. Press enter to keep the current choice[*], or type selection number: 4
  16. update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode.
  17. root@bld-bei-016:~# java -version
  18. openjdk version "1.8.0_111"
  19. OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-3~12.04-b14)
  20. OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)









阅读(1552) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:Ubuntu下制作U盘启动盘,安装Fedora19

给主人留下些什么吧!~~