Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a quick question that might just have a very simple solution.
I recently installed the Java 2 SDK in /usr/java/j2sdk1.4.2_05 and I'm running Mandrake 9.
All my compiling works as expected but I'm looking for an easier way to compile without having to run the command "cd /usr/java/j2sdk1.4.2_05/bin" everytime I open up a new Konsole.
Basically, I'm looking to run java commands such as "javac" and "java" from any location. For example:
mike@localhost mike]$ java
bash: java: command not found
Above is the result I get(my directory is /home/mike/).
If you have a solution to this problem or know somewhere to look, I would appreciate your help.
You should add the directory containing the java and javac exeutables to your $PATH environment variable. $PATH usually contains dirs such as /bin, /usr/bin, /usr/local/bin, /usr/X11R6/bin and so on - directories which the shell searches for executables.
Try typing PATH=$PATH:/usr/java/j2sdk1.4.2_05/bin and then type java -version from the shell prompt. Now you have added the directory to your $PATH, but only in the current shell (the open terminal - when you start another one it won't be there).
Open up your ~/.bashrc and add the line we typed above:
Code:
PATH=$PATH:/usr/java/j2sdk1.4.2_05/bin
In order to make sure ~/.bashrc is parsed everytime we start a new shell, be it a login shell or not, we need to add this to ~/.bash_profile:
Code:
if [ -f ~/.bashrc ]
then
source ~/.bashrc
fi
The above snippet checks if ~/.bashrc exists and is a file. If it does exist it will be parsed. Now you should have access to java and javac no matter in what directory you are currently located.
You may also want to set the $JAVA_HOME and $CLASSPATH variables in a similar way. For more info on that check out the documentation on java.sun.com.
Håkan
Edit: I see Tink beat me to it. Oh well. Two different ways of doing the same thing don't hurt.
Sorry, but you will have to bear with me here a little bit, I'm in my new stages of linux.
I don't follow along when you say "~/.bashrc or ~/.bash_profile" or "Replace your relevant bits with your actual path to the sdk". Where do I find these files/directories?
Unfortunately, I'm not to savvy yet on this stuff, so more basic instructions would be more than appreciated.
Thanks again,
Mike
Edit: I have tried Tink's method, didn't work for some reason...still get the same result.
Tink,
Still getting the same reply as before with the new file.
However, I am able to run the command after typing in the PATH command, but as expected, once I close the Konsole down and open it again, I am not able to.
Ahh, thank you for your help everyone. I figured out that '~' stood for, in my case, /home/mike/. Everything is in working condition exactly as I had hoped.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.