justlinux.com
Fri, 12-Mar-2010 17:36:01 GMT
internet.com
Forum: Registered Users: 73696, Online: 348
nhfs Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home Home

Help File Library: Installing JDK


Written By: Salmon

So you want to be able to use the Java Developers Kit in Linux, eh? I don't blame you. Linux is the superior developing enviroment, and Java is no exception. Even if you have no plans on writing any Java applications, there are an increasing number of existing applications that are either enhanced by or require your system to have Java support. Furthermore, Java has really been in the news lately, and this is your opportunity to get involved in all the fun!

The current production release for Linux is 1.2.2. Version 1.3 (for Linux) is in beta, although the official release is very near, so I'm not going to be talking about that in this Help File. If you would like to give 1.3 a try then you can download it here.

I just want to let you know that I'm making a couple of assumptions before we start:

    1. You already have Linux up and running (duh).
    2. You have at least a basic knowlege of how to navigate and issue commands on your system.
    3. You're installing the JDK for system wide access, and not just for a single user (you). If you prefer the latter, then just replace any references to /etc/profile to ~/.bash_profile, and install the package somewhere in your home directory.

So enough chatter already. Here's where to get it and how to install it.

1. The first thing you need to do is get the software. Sun has released the final version of JDK 1.2.2 for Linux (the guys at Blackdown deserve all the credit), and you can download it from this link. Note that this is a hefty download for a dialup connection (~21 MB), but the option exists to download it in smaller segments. I'll be proceeding as though you have the file in one peice.

2. Decompress JDK 1.2.2 by issuing the following command:

    tar -xvzf jdk1_2_2-linux-i386.tar.gz
    If you're curious, the z option in -xzvf tells tar to filter the file through the gunzip program. Anyway, the above command should create a directory called jdk1.2.2 that contains everything you need.

3. This is where you have to make some of your own calls. Namely, where to install the package. To be proper, I think the experts would probably say to put it in /usr/local/, but you do it however you want. If you're going to model the way I've installed it, then follow along.

    --first you need root privileges so issue commands in this order:
      su (and enter the root password when prompted)
      mv ./jdk1.2.2 /usr/local/ (to move the directory to the desired location)

4. Now you have to tell your system where everything is at. Open up your system wide bash enviroment file in your favorite text editor. The location should be /etc/profile. Add the following lines to the end of the file, save, and exit.

    export JAVA_HOME=/usr/local/jdk1.2.2
      #the above line tells the system where to find the Java home directory.
    export PATH=$JAVA_HOME/bin:$PATH
      #the above line adds the Java home directory to your path.
    export CLASSPATH=./:~/java/classes
      #the above line tells Java where to find the classes it may need. You can add other directories at your discretion, just separate them with a ":"

5. This is all you need to do as root so let's exit superuser mode (exit)

6. Issue source /etc/profile to incorporate the enviromental changes you just made into your current shell If you're working from an X-terminal window, then this will only affect that window. The next time you log in the changes will apply automatically across the board. While not required, you might also want to make two directories to store all your candy-like java code(mkdir ~/java; mkdir ~/java/classes). This is only for organizational purposes.

7. OK, now we can try it out! Open up your favorite text editor, create the following file, and save it as test.java:
Note: smaller font was used for formatting issues

    public class test {
    
         public static void main (String[] args) {
    
         System.out.println ("It works! Three cheers for JustLinux.com!");
    
         }
    
    }

8. Now run the following two commands:

    javac test.java
    java test

    If you get an error on the first command (which complies the program) then make sure that your test.java file is correctly written. The second command should produce the expected text.

9. That's it. Not to bad, eh? Hopefully, this was of some help to people and not too confusing! As always, feel free to offer some feedback.

-B

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
internet.commerce
Be a Commerce Partner












The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers