3

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 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.

Fnux
  • 145
  • 1
  • 5
  • `man 5 sudoers`, section `Command environment`. You can also do `su -` for a full login shell. – n. m. could be an AI Mar 23 '13 at 11:02
  • Thank you n.m. I've read the complete man but I didn't find anything related to CLASSPATH. Further, I'm a newbee on Ubuntu (and Linux in general) and may be a little dumb. Where and what should I add into sudoers (using visudo) to make my needed changes? TIA. – Fnux Mar 23 '13 at 11:44
  • Use `visudo` and look for `env_keep` sections. – n. m. could be an AI Mar 23 '13 at 11:50
  • There's not going to be anything in `sudo` that is specific to Java / JVM (`CLASSPATH`), but it does have flexible options and configuration control for how to handle the environment. – Randall Schulz Mar 23 '13 at 14:49
  • Sorry Randall, but the thing to be with sudo is that it "kill" the CLASSPATH that is used both by Scala AND Java. So, it's not only a question of /etc/sudoers but also to /etc/environment and since I'm a newbee, it's quite difficult to find detailled answers to set such parameters. Anyhow, thanx fot your input. – Fnux Mar 26 '13 at 01:20

1 Answers1

1

You could use the env_keep configuration option in sudoers and add "CLASSPATH" so that the CLASSPATH environment variable is carried into the sudo environment. This would only work if CLASSPATH is already set in your home environment, but it sounds like you've already got that far.

This discussion on the Ubuntu Forums might help.

Arkanon
  • 182
  • 1
  • 8
  • Thanx Arkanon and yes I did that too and this works for Ubuntu 10.04 LTS. Unfortunately, this doesn't work as expected with the 12.04 LTS. e.g. when doing so, you can't anymore start sudo gedit bla bla bla without getting an error like : Cannot open display! However, thanx again for the trick. So, with the 12.04, the only solution I found working is to disable the line Defaults env_reset of /etc/sudoers and add the line CLASSPATH=$CLASSPATH:/usr/share/java/scala-library.jar into /etc/environment for Ubuntu 12.04 LTS. – Fnux Mar 26 '13 at 01:25
  • Hmmm, have you seen this http://askubuntu.com/questions/186015/cannot-open-gedit-display-on-ubuntu-server-12-04 which seems to relate to the same problem? – Arkanon Mar 26 '13 at 20:22
  • Hi Arkanon. And yes, I also already read this stuff! BTW, I dindn't do so within a "server" without a GUI installation but from a full "desktop" installation using Gnome and Unity! So, I repeat putting the line Defaults env_keep=CLASSPATH into /etc/sudoers with Ubuntu 12.04 produces this "strange" behavior (because I don't want to say "bug") when this problem doesn't occur with Ubuntu 10.04! Thanks to Canonical' Devs for such a "dumb" change"! :=( – Fnux Mar 28 '13 at 05:52