aspose file tools*
The moose likes Linux / UNIX and the fly likes JDK, path problem in Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "JDK, path problem in Linux" Watch "JDK, path problem in Linux" New topic
Author

JDK, path problem in Linux

Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
I downloaded the j2sdk-1_4_0-linux-i386-rpm.bin and than I did the following:
1. make file executable
# chmod +x j2sdk-1_4_0-linux-i386-rpm.bin
2. run executable
# j2sdk-1_4_0-linux-i386-rpm.bin
3. install rpm created
# rpm -ivh j2sdk-1_4_0-fcs-linux-i386.rpm
4. add java "bin" path to PATH variable by adding line to file
"/etc/profile"
PATH=/usr/java/j2sdk1.4.0/bin:$PATH

Here is part of the profile file:

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

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

What I did wrong I cannot understand?
when I do: javac Mike.java .. I got the error message
bash: javac: command not found
which java
/usr/bin/which: no java in (/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/root/bin)
Please advice... Thanks
Carl Parrish
Ranch Hand

Joined: May 03, 2002
Posts: 60
Did you re source your profile? If you don't know what I'm talking about logout then log back in and then try. if that doesn't work post back here.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16141
    
  21

You're not exporting your updated PATH. Might be the problem...


Customer surveys are for companies who didn't pay proper attention to begin with.
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
I logget out and than login again ... It works
However, when I login as a user(not a root) it doesn't work .. DO NOT KNOW WHY.
THANKS
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
you need to edit the classpath for all users... not just root. you probably just edited root's classpath...


what?
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
When I setup the path I logged as a root and modify the file /etc/profile. What file I need to modify that all users can compile the Java programs.
Thanks
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
on my Redhat 7.2 machine i edit the ~/.bash_profile file for each user.
what distribution of linux are you running?
[ May 21, 2002: Message edited by: Greg Harris ]
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Red Hat 7.3
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
okay, maybe i can help...
login with your normal username and give the following command in a terminal window:
pico ~/.bash_profile
that will open your profile file in the terminal window.
add your classpath and path to the file, save the file and reboot to make the changes take effect.
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
Does it possible to modify 1 file as a root and all users can use JDK? Or I have to modify for each user separetly.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
I'd like to know how to do this as well - I'm pretty sure that on the old Unix systems like SCO and AIX that I used to use, you could edit the /etc/.profile and all users would process it before processing their own .profile.
This might have been something we scripted ourselves though. How would you call a central .profile from the user's .bash_profile?


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
/etc/profile (note, no ',') is processed before any of the other files for all Linux versions that I'm aware of.
What is probably happening is that somewhere after you set up your path, something else is doing a direct assignment, without including the previous value, so it is getting ignored.
Try to find where each of the other entries on your final path are being set (/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/root/bin) and put something like
/bin/echo "before 1: path='$PATH'"
/bin/echo "after 1: path='$PATH'"
around each path assignment (changing the numbers, natch) to see where your changes are getting ignored. If if these messages don't come out on the console , add a redirect to a known file somewhere, and look at it after you have logged on.
The underlying trick of all this is to treat system administration like a programming problem, and debug it using the tools you have available.
Let us know if you find the problem.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Mis Uszatek
Greenhorn

Joined: Jul 17, 2002
Posts: 1
Notice the 'pathmunge' function. What it does is either prepend or append a single path top the PATH variable, depending on whether or not the 'after' argument is present:
To prepend /some/path to PATH

To append /some/path to PATH

This is similar to other entries in /etc/profile that use this function. Simply make sure to use pathmunge after it has been defined and before it becomes meaningless, that is before the line

And no, it does not make any sense to modify each user's ~/.profile separately. To provide a system-wide setting you should modify the system-wide /etc/profile instead. Commands in it will be executed upon each user's login.
Mark Fletcher
Ranch Hand

Joined: Dec 08, 2001
Posts: 897
Hi,
Best Practices Question here.
Im using SuSE7.3 with JDK 1.4. I installed the Linux bin file from java.sun.com (not the rpm) and added to the end of /etc/profile


My question is: Is it better to add these variables to profile, or on a user by user basis?
Best Regards,
Mark


Mark Fletcher - http://www.markfletcher.org/blog
I had some Java certs, but they're too old now...
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Mark Fletcher wrote: Is it better to add these variables to profile, or on a user by user basis?
The answer, as always, is "it depends".
If you only ever have one version of Java on your system, and you want everybody to get the new version at the same time when you change it, then a single setting in /etc/profile is best. Beware, though, than each new release may break something (1.3 moved some stuff from com.sun to javax; 1.4 introduced the new "assert" keyword and can break JUnit tests, and has changed some of the JDBC classes etc.), so you need to make sure all users understand the impact of an upgrade.
If you have more than one version of Java on your system, and different users need the ability to choose which one they use, then the only solution is local configuration for each user. beware though, that if you retire an old version, some users may syill be using it, and you will have to support all the versions on the system and advise all the users about configuring which Java to use.
It's a tradeoff. What's your situation?
Mark Fletcher
Ranch Hand

Joined: Dec 08, 2001
Posts: 897
Hi,
Im the only one using the Linux box, at home. It connects to my Windows XP box and I do a lot of my development on the Windows XP box, then I transfer it over to the Linux box.
Im using the Linux box mainly as an internal web server, with MySQL. J2EE/Tomcat/J2SE is also set up. Ive also just started playing about with Samba. The box is great for learning Linux on.
However at some point Id like to apply the skills I learn at home in the workplace, and so picking up these "best practices" is very useful to me.
Eventually Id like to migrate away from the Windows box and onto Linux completely, but there are still a few apps (read games) that I cant shake! I use KDE3 as my Windowmanager and Im impressed with how its come along.
Cheers!
Mark

[ July 18, 2002: Message edited by: Mark Fletcher ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDK, path problem in Linux