Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1152073
  • 博文数量: 115
  • 博客积分: 950
  • 博客等级: 准尉
  • 技术积分: 1734
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-08 20:46
文章分类

全部博文(115)

文章存档

2015年(5)

2014年(28)

2013年(42)

2012年(40)

分类: LINUX

2014-05-16 09:06:02


Ref:  

If you have installed Ubuntu from scratch, most probably the java package is not installed by default. The java package is necessary to run any java-based app, including running java applets in the browser. While you may not use it it all the time, it is still handy to install it. When you need it, it is there ready to be used.

In the past, Sun JDK was the default java package in Ubuntu. After Sun Microsystem was acquired by Oracle in 2010, Ubuntu (and various distros) switched the java package to the fully open-source OpenJDK as the SUN JDK no longer contain codes that are fully open-sourced.

OpenJDK is community-built and is (almost) 100% similar to the SUN JDK. You can easily install OpenJDK in Ubuntu via the Ubuntu Software Center, by clicking or running the command:

点击(此处)折叠或打开

  1. sudo apt-get install openjdk-7-jre


Personally, other than some minor font rendering issue with OpenJDK, I have not experience any major problem with OpenJDK. That could also because I don’t use many java-based apps in the first place. However, if you have a specific java-based app that don’t run well in OpenJDK, you can switch to the SUN JDK instead. Here is how you do it:

The hard way

This method requires you to install SUN JDK 7 manually. It is a good way for you to learn the trick.

1. Download the SUN JDK 7 to your home folder.

2. Extract the tar file.

3. Move the extracted file to the “/usr/lib/jvm/” folder:

点击(此处)折叠或打开

  1. udo mv jdk1.7.0_04 /usr/lib/jvm/
4. Install SUN JDK 7 in your system:

点击(此处)折叠或打开

  1. sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_04/bin/javac 1
  2. sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_04/bin/java 1


5. Set the environment variables:

点击(此处)折叠或打开

  1. sudo update-alternatives --config javac sudo update-alternatives --config java
You will see an option like the screenshot below:

java-update-alternative

Enter the option that corresponds to the SUN JDK package. Press Enter.

That’s it.

To test your java:

点击(此处)折叠或打开

  1. java -version
You should see something like this:

java-version

The easy way

If you don’t want to manually install the SUN JDK, you can do it via a PPA. Since there is no official PPA for SUN JDK, you will have to grab a custom PPA that comes with the java package. Note that custom PPAs might add extra software sources to the repository, and cause your system to be bloated or even have conflicts with other apps. So bear in mind the risk involved.

There are several PPAs out there that come with SUN JDK, one that you can use is “webupd8team/java

点击(此处)折叠或打开

  1. sudo add-apt-repository ppa:webupd8team/java
  2. sudo apt-get update
  3. sudo apt-get install oracle-java7-installer

This should install SUN JDK 7 in your system.

Even after you have installed the java package, you will find that the java applet in your browser won’t run. If you are using the OpenJDK, here is another package that you need to install:

点击(此处)折叠或打开

  1. sudo apt-get install icedtea-7-plugin
For Oracle java, run the commands:

点击(此处)折叠或打开

  1. mkdir ~/.mozilla/plugins
  2. ln -s /usr/lib/jvm/jdk1.7.0_04/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins
If you are using a 64-bit system, remember to change the “i386″ to “amd64“.

Once install, restart your browser. The java applet should run now. To test if Java is working in your browser, go to . If installed correctly, you should see a “Your java is working” message.


阅读(749) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~