Operating Systems > Linux and UNIX

Setting up java help

(1/2) > >>

shuiend:
ok for skool i am startin to learn java. Our teacher says we have to use jcreater in windows. i say fuck that. I just installed the JDE and JRE on my red hat 9 box. Now how do i set my paths for users to there. I need to be able to use javac and such. the directory of where it istalled is /usr/java.

Copperhead:
You need to add the bin directory of your Java installation to your PATH in /etc/profile. You separate your directories with a colon (    

#Example /etc/profile

PATH="/usr/bin:/usr/local/bin:/bin:/path/to/java/bin"

Write and quit that file, and then source it so you don't have to reboot.

$ source /etc/profile

That should do it. To test it do this:

$ java -version

It should return 1.4.1 or something along those lines.

Hope that helps.

[ May 14, 2003: Message edited by: Copperhead ]

shuiend:
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
   if ! echo $PATH | /bin/egrep -q "(^| $1($| " ; then
      if [ "$2" = "after" ] ; then
         PATH=$PATH:$1
      else
         PATH=$1:$PATH
      fi
   fi
}

# Path manipulation
if [ `id -u` = 0 ]; then
   pathmunge /sbin
   pathmunge /usr/sbin
   pathmunge /usr/local/sbin
fi

pathmunge /usr/X11R6/bin after

unset pathmunge

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
       . $i
    fi
done

unset i


thats my profile. Now where in that do i change it? i looked for the path book i am not sure how to put it in thwere

Copperhead:
Put this line: "pathmunge /path/to/java/bin after" (without quotes) right before the line that reads: "pathmunge /usr/X11R6/bin after"

So, /etc/profile will look something like this:

#...stuff

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^| $1($| " ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# Path manipulation
if [ `id -u` = 0 ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi

pathmunge /path/to/java/bin after
pathmunge /usr/X11R6/bin after

# stuff...........

I am not sure if you need to do this on Red Hat or not, but do this next:

$ source /etc/profile

That will make your new profile take effect with the added PATH entry, and save you from rebooting. Do this to test it out:

$ echo $PATH

You should see /usr/java/j2sdk1.4.1/bin or something like that.  Also, you can try:

$ java -version

which will return "Java SDK Version 1.4.1" or something like that.

You could also just edit the .bash_profile file in your /home/user directory. The PATH that is in there is only for THAT particular user. /etc/profile is system-wide, and thus probably a better option.

Just in case anyone cares, this "pathmunge" business is just a function to test to see if the root user is logged in (that is what the line "if [ `id -u` = 0 ];" is doing), and then by way of the pathmunge function, sets the Root User's PATH variable to the three paths it has listed (/sbin, /usr/sbin, /usr/local/sbin.) Apparently, there is some sort of security hazard with the .bash_profile file in the /root home directory, so Red Hat came up with this measure to replace .bash_profile with this pathmunge() function located in /etc/profile.

[ May 15, 2003: Message edited by: Copperhead ]

Calum:
is the pathmunge thing RH specific then? by that i mean it won't work with other systems, in particular i mean that i use slack, i don't have any pathmungeing going on in my /etc/profile (and users do not have a .bash_profile either, they all just get their settings from /etc/profile) and what i really mean is:
1) if i added a lot of pathmunge to my /etc/profile would it just not work because it's not red hat?
2) if i copied /etc/profile into /root as .bash_profile would i replicate the vulnerability, or is that red hat specific also? (what is this vulnerability anyway?)

Navigation

[0] Message Index

[#] Next page

Go to full version