This tutorial will guide you on how to install JDK (Java Development Kit) on Linux. Since I use Centos 5.4 x86_64 in everyday life, this guide is showing you how to install JDK in Centos 5.4 64bit. It must work in any other Linux distro such as Slackware, Fedora, Ubuntu et cetera.
If you install a Linux OS, the developers usually already included a JVM to the system to run some programs that need Java. Mostly they included OpenJDK for the JVM.

But I don’t like to use OpenJDK because some Java platform like JavaFX will not run using OpenJDK.

UPDATE! Java SE 6 (JDK 1.6) Update 24 (file name: jdk-6u24-linux-i586.bin) is now available. You can download the file from Java SE Downloads page. Java SE 7 (JDK 1.7) Binary Snapshot build b132 also has been released. If you want to download and install the Java SE 7, you can get the file fromJava SE 7 download page with the file name jdk-7-ea-bin-b132-linux-i586-03_mar_2011.bin. This tutorial should be applicable for those version.

1. Download the JDK

The JDK can be downloaded from its official website. At the time this tutorial was written, the JDK version is JDK 6 Update 17. Click the Download button then you will be forwarded to Java SE Download page. You can select the Java platform to suit your system.

Since I use x86_64 of Linux, I choose ‘Linux x64′ for the platform. Then click ‘Continue’ button. You can skip for the ‘Log in for Downloads’ optional window. Then select from the available files.

Choose not the ‘rpm’ file because we will install the JDK in a folder as we want to.

2. After the download is complete, unpack the file by executing it.

First you have to make it executable.

[fuad@centos Downloads]$ chmod +x jdk-6u17-linux-x64.bin
[fuad@centos Downloads]$ ./jdk-6u17-linux-x64.bin inflating: jdk1.6.0_17/README.html
creating: jdk1.6.0_17/include/
inflating: jdk1.6.0_17/include/jni.h
creating: jdk1.6.0_17/include/linux/
inflating: jdk1.6.0_17/include/linux/jawt_md.h
inflating: jdk1.6.0_17/include/linux/jni_md.h
inflating: jdk1.6.0_17/include/jvmti.h
inflating: jdk1.6.0_17/include/jawt.h
inflating: jdk1.6.0_17/include/jdwpTransport.h
inflating: jdk1.6.0_17/include/classfile_constants.h
inflating: jdk1.6.0_17/COPYRIGHT
Creating jdk1.6.0_17/jre/lib/rt.jar
Creating jdk1.6.0_17/jre/lib/jsse.jar
Creating jdk1.6.0_17/jre/lib/charsets.jar
Creating jdk1.6.0_17/lib/tools.jar
Creating jdk1.6.0_17/jre/lib/ext/localedata.jar
Creating jdk1.6.0_17/jre/lib/plugin.jar
Creating jdk1.6.0_17/jre/lib/javaws.jar
Creating jdk1.6.0_17/jre/lib/deploy.jar Java(TM) SE Development Kit 6 successfully installed. Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Sun products, services and training
* Access to early releases and documentation Product and system data will be collected. If your configuration
supports a browser, the Sun Product Registration form for
the JDK will be presented. If you do not register, none of
this information will be saved. You may also register your
JDK later by opening the register.html file (located in
the JDK installation directory) in a browser. For more information on what data Registration collects and
how it is managed and used, see: http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html Press Enter to continue..... Done.

A folder ‘jdk1.6.0_17′ will be created.

3. Move the ‘jdk1.6.0_17′ folder to a safe place

We will move this folder to a place as you want to. You can move it to /opt folder, leave it in this directory or to anywhere in the system. I prefer to move this folder to /usr/local. So move it there.

[fuad@centos Downloads]$ sudo mv jdk1.6.0_17 /usr/local/

Here in the /usr/local/ directory, we will create a symbolic link to jdk1.6.0_17 named as ‘java’

[fuad@centos Downloads]$ cd /usr/local/
[fuad@centos local]$ sudo ln -s jdk1.6.0_17 java

Now the JDK is installed in /usr/local/jdk1.6.0_17 and linked to /usr/local/java.
We need to add /usr/local/java/bin folder to the system PATH. If it is only for your account, add it in .bash_profile file in you home directory. In Slackware, it should be in .profile file. To make it system wide environment, add it in the /etc/profile.

Edit a line in .bash_profile to be similar like below:

PATH=$PATH:$HOME/bin:/usr/local/java/bin

This way the PATH will be automatically set at boot time.

You can also set the PATH immediately by using a command below:

$ export PATH=$PATH:/usr/local/java/bin

Now you can call java directly in your shell:

$ java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)

4. Upgrade to the latest version

If there is a new JDK version released by Sun/Oracle and you want to upgrade to the latest version, you can simply follow the steps above. Except for the third step, after moving the new JDK version to /usr/local/ folder, you need to remove the existing ‘java’ folder in the /usr/local/ directory and re-create the symbolic link again.

For example, today on May 18th, 2010, I checked to the java.sun.com website that the current latest version of the JDK is JDK 6 Update 20. So after following step 1 and 2, we remove the ‘java’ folder and re-create the symbolic link again to the ‘java’ folder.

$ sudo rm -rf java
$ sudo ln -s jdk1.6.0_20 java

To make sure it has been successfully upgraded, you can check the current java version.

$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode)

最新文章

  1. python 字符编码 转换
  2. spring mvc 第一天【注解实现springmvc的基本配置】
  3. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q95-Q98)
  4. MongoDB—— 读操作 Core MongoDB Operations (CRUD)
  5. 如何解决虚拟机Mac OS X 不支持二进制编译问题()
  6. PDF打印
  7. Xcode 项目文件介绍
  8. UVa 10674 (求两圆公切线) Tangents
  9. ASP.NET-FineUI开发实践-7
  10. 快速美眉(FastMM)使用手记
  11. error 和 exception 有什么区别?
  12. 利用python进行数据分析之数据聚合和分组运算
  13. 【linux驱动分析】之dm9000驱动分析(六):dm9000_init和dm9000_probe的实现
  14. 【转】虚拟机下安装小红帽Linux9.0图解
  15. (转)MyBatis在插入的数据有空值时,可能为空的字段都要设置jdbcType
  16. 我的Spring学习记录(二)
  17. poj2029 Get Many Persimmon Trees
  18. TLS1.3&TLS1.2形式化分析
  19. Django--cookie(登录用)
  20. web Deploy发布问题

热门文章

  1. Oracle 存储过程实例2
  2. OC面向对象多态笔记
  3. 复习linq
  4. Careercup - Facebook面试题 - 5110993575215104
  5. 安装 SQL SERVER PROFILER
  6. SilverLight页面跳转(转载)
  7. IT 基础设施
  8. C# 中的命名规则
  9. eclipse 或MyEclipse将工程进行移动的时候会对@Override报错的处理方法
  10. 黑马程序员-C#学习笔记