Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.

share|improve this question

migrated from Mar 23 '13 at 20:19

This question came from our site for professional and enthusiast programmers.

man 5 sudoers, section Command environment. You can also do su - for a full login shell. – n.m. 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. 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 1:20
up vote 1 down vote accepted

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.

share|improve this answer
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 1:25
Hmmm, have you seen this… 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 5:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .