Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have install Sun Java 6 on an Ubuntu server and set an environment variable in the default profile as per the instructions at http://www.edugate.ie/workshop-guides/shibboleth-2-identity-provider-installation-linux-debian-or-ubuntu

I then try to run an installer for a Java servlet - but when I run it as myself, it cannot create the required directory in /opt. When I run it as sudo, I am told that JAVA_HOME is not correct and it doesn't even start the installer - shouldn't this be coming from /etc/profile like it is for my normal user?

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

instead of running it via sudo, run it in a root shell...
sudo su
then check your environment variables and fix as necessary echo $JAVA_HOME
then run the installer or set the variable if it needs setting

share|improve this answer
    
ok - how do I check and fix? –  HorusKol Jan 7 '11 at 6:12
add comment

Try this:

export JAVA_HOME=/path/to/java/home

example:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

Then run your applet like below:

sudo env JAVA_HOME=$JAVA_HOME your_applet_or_script

example:

sudo env JAVA_HOME=$JAVA_HOME /usr/bin/eclipse

hope this helps.

share|improve this answer
add comment

Very generally speaking (and just looking very briefly at those instructions you linked to), you want to run tomcat as a non-root user. This is both safer & more convenient (since you don't have to do everything as root).

But that also means tomcat will have to run on a higher port (e.g., 8080 or such). And in order to service client requests on the more common port 80, you run Apache on port 80 in front of Tomcat (which the instructions also outline), and Apache connects to tomcat via mod_jk on another port (e.g., 8009 (http) or 8443 (https) or such).

Now, in order to install Java apps in Tomcat, just chown / chmod your tomcat directory so that your "web user" (possibly your own non-root user account) can write to it. For example,

 $ sudo mkdir /opt/tomcat

And then typically chown (or just chmod):

 $ sudo chown my_user:my_group /opt/tomcat

Now, do everything as a non-root account, and no sudo is necessary. It might still be a good idea to have a semi-restricted "web-admin" account if this is a shared server, rather than using your own login.

share|improve this answer
    
While this is a very good answer to some question - this isn't the answer to my question at the top... –  HorusKol May 9 '11 at 13:18
    
Yes, there two correct answers: login & do everything as root (the accepted answer), or set things up "correctly" (this answer). Long story short, if you install a container as "root", then you have to install and run everything inside that container as "root" (using sudo won't do). Heads will bang against walls until you surrender & just set things up "right" (from personal experience). It's kind of like in windows, where you end up being "administrator" to do anything. But you don't want to end up in this situation in linux, where you login as root, stay as root, "rm -fr /" as root... –  michael_n May 23 '11 at 21:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.