Re: My shell can't find Java

From: John Fereira (jaf30_at_cornell.edu)
Date: 07/31/04


Date: Sat, 31 Jul 2004 12:41:54 GMT

Oscar kind <oscar@danwa.net> wrote in news:p57st1-3ff.ln1@odin.asgard:

> IOANNS MANOLOUDIS <alien@mail.otenet.gr> wrote:
>> I am using Mandrake linux 10. I downloaded java with netbeans from Sun
>> and i installed it in /usr/local
>> Each time I type java I get an unknown command error.
>> I know that I need to make some modifications to some environmental
>> variable. Pleeeeeeeeeeeease can you tell me how can i do that?
>> I need to make it working so that every application that uses java
>> (such as Kdevelop or Openoffice) can find it.
>
> You need to add the java executables to your ${PATH}. Personally, I've
> done this (as root), because /usr/local/bin is first in my ${PATH}:
>
> cd /usr/local/bin/
> ln -s /usr/local/j2sdk1.4.2/bin/* .
>
> This method has the advantage I don't have to clutter my ${PATH} with
> all installed programs, but if I ever use a differnt java version (1.5
> comes to mind), I'll have to adjust the links.

Here's how I do it.

First, how you set environment variable depends on what shell you're using.
If you're not sure try typing echo $SHELL

If you're using sh or (more likely) bash the syntax (typically found in
.profile in your home directory) is

   PATH=/usr/local/bin:/usr/bin:/usr/local/j2sdk1.4.2/bin
   export PATH

If you're using csh (or tcsh) (typically done in a .login file in your home
directory) use:

   setenv PATH /usr/local/bin:/usr/bin:/usr/local/j2sdk1.4.2

When adding directory PATHS for applications that I might update or require
different versions I use a separate variable.

   JAVA_HOME=/usr/local/j2dk1.4.2
   PATH=:/usr/local/bin:/usr/bin:${JAVA_HOME}/bin
   export JAVA_HOME PATH

The, if I want to change versions I just change the value of JAVA_HOME with
changing the order of my search path. Note that some applications require
that the JAVA_HOME variable be set (i.e. Tomcat)

If you need to switch versions of compilers back and forth depending on what
you're compiling, put these statements in a separate files (one for each
version). Then use the "." command to read the file and put the environment
in your current shell. For example, if the commands are located in a file
called setpath.sh you can execute the following:

   . setpath.sh

You can also use the . command in your .profile file so that you can
"include" you path setting commands at startup.

   



Relevant Pages

  • Re: Calling a shell function
    ... Java File object to rename it like a Unix mv command. ... John Bowling wrote: ... It can be done easily by call shell functions ...
    (comp.lang.java)
  • Re: Piping output of one command into builtin "read" command
    ... #Java is revision 1.4 ... environment variables are, like arguments, strings passed from ... command to command. ... I thing you're confusing it with shell ...
    (comp.unix.shell)
  • Re: [SLE] PID file for java process?
    ... "java -jar jarfile.jar" launches the program, ... You can unpack a JAR file using either the "jar" command or the zip, ... interactively or via a shell script. ...
    (SuSE)
  • Re: Java on ubuntu
    ... In the GNU_BUILD command, changing i386 to i586 too was unsuccessful. ... That hasn't changed the default java setting and I am really out of ideas now. ... the instructions in RestrictedFormats wiki page, the java bin name must be exactly as it is written in the wiki -- u look like u have the right name; did you install java-commons package also? ... environment correctly and was pleased with the results. ...
    (Ubuntu)
  • Re: A constructive debate: Eclipse or NetBeans?
    ... that Linux and command-line driven languages like OCaml are so much more ... That's because most people never learn to use a command line or a simple ... Trying to run other people's OpenGL-based Java demos from the web I find ... OpenGL). ...
    (comp.lang.java.softwaretools)