linuxnewbie.org.gif
Tuesday, 12-Dec-2000 10:40:11 EST
Newbized Help Files articles discussion board bookshelf sensei's log advertising info

How do I install Java on my Linux Computer?
Written By: Greg Brouelette

[-Previous Page-]

Close your editor and type ENV to see if the JAVA_HOME and new Path has taken effect (if you're in a gui like KDE or GNOME you may have to close and restart your terminal window for these changes to take effect)

Lets test it. Type the word "java" (without the quotes) in a terminal window and see if you get something like this:

Usage: java [-options] class [args...]

and so on.

If you get the message

java:command not found

then your path is not correct. Essentially the java and javac programs are in that bin directory and you want to get access to them.

The JAVA_HOME environment variable is used by other programs that need to know where your jdk is (like Star Office for example).

There is one more change you'll need to make. For Java to work it needs to know where the class files are for any program that you're writing.

For our example lets make a directory under our home directory called myjava. Do this by typing:

mkdir myjava

This is where our example programs are going to be. Now we need to tell Java where our programs will be by adding the following line to our .bashrc ( or .bash_profile ) file in exactly the same way we added the JAVA_HOME and PATH lines earlier.

export CLASSPATH=.:~/myjava

(Remember, you may need to close and reopen your terminal window to make this change take effect).

Let's test it! Let's write a "Hello World" program in Java and make it work.

Go to your myjava directory and write the following program saving it as Hello.java

import java.awt.*;

public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

Be sure that the name of the class and the filename are exactly the same (including capitalization). In other words if you write a class called DoThisWeirdThing it MUST be saved in a file called DoThisWeirdThing.java Back at your command line type:

javac Hello.java

If you typed everything correctly you'll get a prompt again. Type ls to see the contents of your directory and you should see a Hello.class file. At your command line type:

java Hello

and you should see the words "Hello World" print out.

If you can make this work then you've got Java installed properly. (That wasn't too hard was it?)

5. Where can I learn more about Java.

I suggest you download the free HTML documentation from www.javasoft.com. It has the entire language referenced via an easy to use browser interface. I always keep this file up in a browser while I program as a quick reference.

I'd also like to suggest the book "Thinking In Java" by Bruce Eckel. I like this book for 2 reasons: One, it's pretty much the best Java book I've found and Two, the entire book is available for free online at www.bruceeckel.com (Although it would be cheaper to buy it than to use up an entire laser printer cartridge printing it out).

All the source code examples in Bruce's book are also available at his web site.

Another good source of Java knowledge is the Java Developers Connection (JDC) which is a free forum that you can join at www.javasoft.com. There are quite a few Java programmers online that can answer your questions.

I hope this helps you install Java on your Linux computer. Please post any questions on the LinuxNewbie discussion board and I'll try to answer them A.S.A.P.

Good Luck!

Greg Brouelette A.K.A. Dru Lee Parsec

2-17-00 ADDITIONAL INFORMATION:

I've received e-mail from several folks saying that they get an error telling them that some shared files are not found when they try to use java or javac. It turns out that this usually means that the glibc libraries are not the latest version. I've not had the problem when installing Mandrake 6.1 but other folks have told me that this has fixed their problems.


[-NHF Control Panel-]
The Linux Channel at internet.com
Linux Planet
Linux Today
Linux Central
Linuxnewbie.org
PHPBuilder
Just Linux
Linux Programming
Linux Start
BSD Today
Apache Today
Enterprise Linux Today
BSD Central
All Linux Devices
SITE DESCRIPTIONS
[-What's New-]
Order a Linuxnewbie T-Shirt
Easy Webcam NHF
Directory Navigation NHF
Installing Snort 1.6.3 on SuSE 6.x-7.x
Customizing vim
The SysVinit NHF
Installing ALSA for the VT82C686 integrated sound
USB Creative Video Blaster II for Linux
Configuring the Intellimouse Explorer in XFree86 V4+
The beginnings of a distro NHF
Getting Past Carnivore?
Getting and Installing PGP
Getting your ATI Rage 128 Working
How to create a multiple partition system
Using Fdisk
Introduction to Programming in C/C++ with Vim
Adding a Hard drive in Linux -- In five steps
Installing ALSA for the Yamaha DS-XG Sound Card
Getting your Diamond Rio Mp3 Player to work with Linux
Bash Programming Cheat Sheet
Installing NVIDIA Drivers for Mandrake
Setting up Portsentry
Hard Drive Speed Tweak for Linux
Sensei's Log
Chat room
Join: Linuxnewbie.org SETI Black Belts!
Send in your news
Click the image to add Linuxnewbie.org to your MyNetscape Page
[-LNO Newsletter-]

[-Archive-]
The beginnings of a distro NHF
Connecting to the Internet using KPPP
Getting your SBLive to work
Unreal Tournament NHF
LWE Day 2 Pictures
LWE Day 1 Pictures
The LNO FAQ!
WoW (Words of Wisdom)
Other sites news
What is Linux?
What is Linux? part deux (ups & downs)
Search newsgroups
The List
ALS Report
Feedback Form
jobs.linuxtoday.com.gif
Match: Format: Sort by:
Search:
[-Quick Links-]

Copyright 2000 internet.com Corp. All Rights Reserved. Legal Notices Privacy Policy

internet.com.gif