How to add CLASSPATH parameters permanently when using sudo?
Hello all,
On Ubuntu 12.04.2 LTS 64bits, when using sudo or sudo -i or sudo su or even su in a session, in order to use both Java AND Scala I need to enter in each terminal the following commands: sudo -i CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar export CLASSPATH Is it possible to make these changes permanent and effective when I boot? I've tried to include CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar into .bashrc of both my user account and the root account but this change isn't taken when using sudo, or sudo -i or sudo su or even su! TIA for any help on this problem. |
Try using su - which gives you a "login" session (as if you logged in as root) so you get all the environment variables set.
I'm not familiar enough with sudo but I would assume that you can start it the same way (as a login session). Hope this helps some. |
I already tried with su
Hello tronayne,
Quote:
However this doesn't solve the problem since I said I also tried with su My problem is then in what file should I add the classpath needed for scala, since adding the line CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar into: - .profile - or .bashrc - or /etc/bash.bashrc - or even into sudoers doesn't work, whenever I use: - sudo - or sudo -i - or sudo su - or even su Someone told me on another forum to read the man 5 sudoers in the section environment but there is absolutely nothing about CLASSPASS to add it into the sudoers file (using visudo). I maybe have a syntax problem but I've also tried to put only CLASSPATH=/usr/share/java/scala-library.jar into the 4 files defined above, but that doesn't work either. Every time I start echo $CLASSPATH, I get an ampty answer when using any combination of "root" session. So, I'm stock with my three command lines (that I've to type each time I open a terminal session): sudo -i CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar export CLASSPATH And this is not practical at all. :banghead: If you've another idea. Maybe it's somewhere into a Java configuration file, but I don't know which one (and trust me, I've googeled a lot these last 4 or 5 days to find an answer that works). Anyhow, thanx again. Fnux. |
Just in case... when you use su - (with the dash) you get a login shell; i.e., the content of /etc/profile, entries in /etc/profile.d and root's .profile are read (su without the dash does not do that, you get no environment settings other than a bare minimum). You can tell if you open a terminal window and type "su -" and you should see root's profile settings.
Another idea -- is there a directory in /etc with scala configuration? Or is there an etc/profile.d directory (with something like "scala.sh" in it? Or a "conf" file for scala? Any of those should be read at boot, login or application start up. As a last resort, try adding your CLASSPATH at the end of /etc/profile or, if you have /etc/profile.d with a file jdk.sh in it (which looks like) Code:
#!/bin/sh Last resort: put a little executable in /root: Code:
#!/bin/sh Code:
chmod 755 whatever Best I can do. Hope this helps some. |
Hi Tronayne,
Thanx again a lot for all these explanations. I'll try all of those tomorrow and I'll let you know. Thanx again and have a nice week-end. PS: I'm using Ubuntu 12.04.2 LTS 64 with Unity, but I'm also using the good old 10.04.4 LTS 64 and gnome and have the same problem with it. |
Solved
Hi tronayne,
Quote:
However, this is how I solved my problem (may be it's not the best idea, but it works for me): a) I put a sign # in front of the line Defaults env_reset of the /etc/sudoers file (using visudo of course). b) Then I put the line CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar just below the lines ENV_SUPATH and ENV_PATH of the file /etc/environment c) Then after a reboot: Now that's magical! :D Now, I still have my CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar environment whenever I use sudo, or sudo -i or sudo su or su oe su - Hope this may help others wanting tu use both Java and Scala symultaneously. Thanx again for all your ideas that forced me to experience a lot more. Kind regards. Fnux. |
Glad you got it.
Something you may want to forget about is "sudo su" -- the redundancy is... worthless? The sudo utility (from the manual page) Quote:
Quote:
What you needed to do was place your CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar environment setting in a place where it would be executed (thus, set) at log in. Your addition of the CLASPATH variable to /etc/environmnet apparently accomplished that. I do not use sudo (in favor of su or su -, personal preference). Digging further into the sudo and sudoers manual pages there are ways to set environment variables, ranging from passing the argument(s) on the command line to command line options -- I'll leave it to you to read about those in the manual pages. Anyway, glad to know you've got it done. |
All times are GMT -5. The time now is 12:51 PM. |