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 a Java program which accesses some property files for it to work through a path which is set as an environment variable. I set the path using export command. The Java jar file which is the executable is placed under some different user, and hence I use the sudo option to run the jar file.

My problem is, when I set the environment variable on a test server, the program runs fine, however, when I make the same config settings on a production server, and try to run it, it shows that the path set for environment variable is null.

I know this has got something to do with the access or perhaps different server configs but as I am new to UNIX, I am not sure where I can start investigating.

Can anyone please help?

share|improve this question
add comment

2 Answers

Environment variables for a user can be set in ~/.profile however since you are running some commands as root this will not work unless you also change roots .profile file.

Another option is to change the file /etc/profile to add the paths and this should work for all users.

share|improve this answer
add comment

Places to check for environment variables

/etc/environment
/etc/profile
~/.profile
~/.bashrc

If you export a variable as userA and then launch the jar using sudo, this variable won't be copied into userA's environment.

A quick workaround is to run the command as:

PATH=$PATH:/your/directory asdf.jar

That will set the PATH for just this invocation of your jar file.

You can also verify what that program's environment looks like by getting its pid and running cat /proc/<pid>/environ

This will show you all environment variables available to your program.

share|improve this answer
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.