Saturday, February 6, 2010
by Less Talk, More Example
The Goal
You can install Sun JDK on Ubuntu Linux using "unpack and run" method not via apt-get.
The Process
- Download the Sun JDK for Linux from http://java.sun.com/
- Open the terminal to extract the package, move to the saved location first:
(I assume you save it to your home directory)
$ cd /home/user
$ sh jdk-6u7-linux-1586.bin - You will be asked "License Agreement" and type yes to Agree.
$ sudo mv jdk1.6.0_07 /usr/local
$ sudo ln -s /usr/local/jdk1.6.0_07 /usr/local/java
- Check the current java that running on your system
$ update-alternatives --list java
/usr/bin/gij-4.2
- After running that command we knew that there is no alternative for java. So, we need to add our new JDK to the alternatives.
$ sudo update-alternatives --install /usr/bin/java java /usr/local/java/bin/java 100
$ sudo update-alternatives --config java
There are 2 alternatives which provide `java'.
Selection Alternative
-----------------------------------------------
* 1 /usr/bin/gij-4.2
+ 2 /usr/local/java/bin/java
Press enter to keep the default[*], or type selection number: 2
$ java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
- Now let's test our new environment, for this purpose we will create simple Java program. Open your favorite text editor, e.g gedit (Application - Accessories - Text Editor) and try this following code.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
- Save it to some location, since this is only a test I would recommend to save it under /tmp directory. I name it Hello.java.
- We need to add /usr/local/java in shell environment variables by editing .bashrc file located in our home directory.
$ gedit ~/.bashrc
- Add the following lines into .bashrc (put these code at the end of file).
JAVA_HOME=/usr/local/java
JAVA_BIN=$JAVA_HOME/bin
PATH=$PATH:$JAVA_HOME:$JAVA_BIN
export PATH
- Save the file and close the editor. Now we need to close our Terminal to take affect. Open the terminal again and try to compile Hello.java. All the things should work :).
$ cd /tmp
$ javac Hello.java
$ java Hello
Hello World! - Done.
0 komentar:
Post a Comment